RE: [PATCH v4 1/1] printf: add support for printing symbolic error names

From: David Laight
Date: Tue Oct 15 2019 - 09:44:35 EST


From: Petr Mladek
> Sent: 14 October 2019 14:03
> 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
>
> Reviewed-by: Petr Mladek <pmladek@xxxxxxxx>
>
> I like the patch. There are only two rather cosmetic things.
>
> > diff --git a/lib/errname.c b/lib/errname.c
> > new file mode 100644
> > index 000000000000..30d3bab99477
> > --- /dev/null
> > +++ b/lib/errname.c
> > +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".

What is thus "true" symbol you are talking about?
Actually you could get rid of the "bool" as well.
unsigned int pos = err > 0;
const char *name = __errname(pos ? err : -err);
return name ? &pos[name] : NULL;
then it is all well defined.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)