[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75Vc1Tk7i1TCtT6RnfyBbt2F_skK8DEQ5iky1=spW06qsdQ@mail.gmail.com>
Date: Mon, 14 Oct 2019 16:10:54 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Petr Mladek <pmladek@...e.com>
Cc: Rasmus Villemoes <linux@...musvillemoes.dk>,
Uwe Kleine-König <uwe@...ine-koenig.org>,
Joe Perches <joe@...ches.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Jonathan Corbet <corbet@....net>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4 1/1] printf: add support for printing symbolic error names
On Mon, Oct 14, 2019 at 4:02 PM Petr Mladek <pmladek@...e.com> wrote:
> On Fri 2019-10-11 15:36:17, Rasmus Villemoes wrote:
> > It has been suggested several times to extend vsnprintf() to be able
> > to convert the numeric value of ENOSPC to print "ENOSPC". This
> > implements that as a %p extension: With %pe, one can do
> > +const char *errname(int err)
> > +{
> > + bool pos = err > 0;
> > + const char *name = __errname(err > 0 ? err : -err);
> > +
> > + return name ? name + pos : NULL;
>
> This made me to check C standard. It seems that "true" really has
> to be "1".
You may guarantee it by using !!.
return name ? name + !!(err > 0) : NULL;
But to me it seems like forgotten use of pos in the other case above.
Anyway, I would rather do
abs(err) in the first place
and simple use name + 1 in the second as you suggested with maybe a
comment that we skip E letter.
> But I think that I am not the only one who is not sure.
> I would prefer to make it less tricky and use, for example:
>
> const char *name = __errname(err > 0 ? err : -err);
> if (!name)
> return NULL;
>
> return err > 0 ? name + 1 : name;
> > +}
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists