[haiku-development] Of errno signedness and standards

  • From: "François Revol" <revol@xxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Tue, 20 Jan 2009 02:51:03 +0100 CET

I've been having a discussion on qemu-devel recently, again about the
issue with errno signedness:
http://article.gmane.org/gmane.comp.emulators.qemu/36145

It appeared what I thought was something else than POSIX actually is
POSIX itself, on the Opengroup website, and which changed its mind at
one point about if errno should be !=0 or >0.
see:
http://www.opengroup.org/onlinepubs/000095399/basedefs/errno.h.html#tag_13_10_10

However it seems too that ANSI C (C89 and now C99) also defines errno
and 2 of the errors (EDOM and ERANGE), as >0.

What I have read from the available drafts seemed confuse enough to
give me a headache. And we aren't changing our errors any time soon
anyway.

However, we should really make sure we didn't miss one of those "bug"
introduced by Linux people (the habit of returning -EFOO seems to have
started in the Linux kernel).

We should make sure people writing software we might one day port are
aware of the issue before starting to use such trick.

Also, I started checking for those in our own sources, and though gcc
doesn't seem to have them a single time, I noticed some suspicious
lines elsewhere in libraries we use...

Either things like
return -EINVAL;

or

return -errno

or even

int err = -EFOO;
...
return err;

or

int err = errno;

return err;

should be fixed. Note intermediate variables can be named otherwise
which makes them harder to detect...

I use this for now:

grep -R '[^A-Za-z]\-\(E[A-Z0-9][A-Z0-9][A-Z0-9]\|err\)' src/

(note E2BIG exists, so not only A-Z must be checked)

If anyone has enough friends at ANSI commitees I suggest they push for
fixing C99 too :)))

François.

Other related posts: