bitwiseworks / libc

LIBC Next (kLIBC fork)
9 stars 4 forks source link

sys/errno.h has numerous guards, _POSIX_SOURCE #124

Closed dryeo closed 1 year ago

dryeo commented 2 years ago

Building mpg123's latest snapshot results in this error,

src/compat/compat.c: In function 'INT123_unintr_write':
src/compat/compat.c:444:59: error: 'EWOULDBLOCK' undeclared (first use 
in this function)

and looking at sys/errno.h around line 112 shows,

#ifndef _POSIX_SOURCE
#define EWOULDBLOCK     EAGAIN          /* Operation would block */

There are also other #ifndef _POSIX_SOURCE guards in the header. One man page has,

EAGAIN or EWOULDBLOCK
              The file descriptor fd refers to a socket and has been
              marked nonblocking (O_NONBLOCK), and the read would
              block.  POSIX.1-2001 allows either error to be returned
              for this case, and does not require these  con‐ stants to
              have the same value, so a portable application should
              check for both possibilities.

So this seems like a bug to me and the guards should be removed. I can make a patch if needed. If there is a good reason for these guards, it would also be good to document it in the header

dmik commented 1 year ago

What makes you think these guards should be removed? These errors are not part of POSIX (see https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html) and that's why they only show up when POSIX is not defined. FreeBSD (which our LIBC is significantly based on) does exactly the same thing (https://github.com/freebsd/freebsd-src/blob/master/sys/sys/errno.h) and I see no reason to change it.

As for mpg123, its compile or link options should be aligned I guess.

Feel free to reopen if you have strong objections.

dmik commented 1 year ago

Well, EWOULDBLOCK seems to be an exception here as POSIX lists it as "shall define" on the page above. I wonder why FreeBSD goes this way and hides it then. There is also ETXTBSY with the same story and perhaps some more. Ok, I will check them all.