<unistd.h> TEMP_FAILURE_RETRY() unusable without extra #include

Florian Weimer fweimer@redhat.com
Fri Jun 20 10:23:43 GMT 2025


> bug or feature? (it's common to all three of bionic, glibc, and musl,
> so if i add the #include <errno.h> to bionic's unistd.h and glibc
> doesn't, that would reduce source portability...)
>
> /tmp$ cat x.c
> #define _GNU_SOURCE
> #include <unistd.h>
> int main() {
>   return TEMP_FAILURE_RETRY(getpid());
> }
> /tmp$ make x
> cc     x.c   -o x
> In file included from x.c:2:
> x.c: In function ‘main’:
> x.c:4:10: error: ‘errno’ undeclared (first use in this function)
>     4 |   return TEMP_FAILURE_RETRY(getpid());
>       |          ^~~~~~~~~~~~~~~~~~
> x.c:3:1: note: ‘errno’ is defined in header ‘<errno.h>’; this is
> probably fixable by adding ‘#include <errno.h>’
>     2 | #include <unistd.h>
>   +++ |+#include <errno.h>
>     3 | int main() {
> x.c:4:10: note: each undeclared identifier is reported only once for
> each function it appears in
>     4 |   return TEMP_FAILURE_RETRY(getpid());
>       |          ^~~~~~~~~~~~~~~~~~
> x.c:4:10: error: ‘EINTR’ undeclared (first use in this function)
>     4 |   return TEMP_FAILURE_RETRY(getpid());
>       |          ^~~~~~~~~~~~~~~~~~
> make: *** [<builtin>: x] Error 1
> /tmp$

I think it's a bug, but the fix is not a one-liner because for glibc at
least, we don't want to #include <errno.h> in <unistd.h> because it will
pull in kernel stuff.

Thanks,
Florian



More information about the Libc-alpha mailing list