From: Eric Blake Date: Wed, 15 Sep 2010 21:25:43 +0000 (-0600) Subject: stdlib: work around MirBSD WEXITSTATUS bug X-Git-Tag: v0.1~3805 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=91935a638321ad61c876153d149ee09fc701c2db;p=gnulib.git stdlib: work around MirBSD WEXITSTATUS bug * lib/stdlib.in.h (includes): Guarantee WEXITSTATUS. * modules/stdlib (Depends-on): Add sys_wait. * tests/test-sys_wait.c (main): Enhance test. * tests/test-stdlib.c (main): Likewise. * doc/posix-headers/stdlib.texi (stdlib.h): Document the bug. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index ffbb1c03e..bacfce312 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2010-09-15 Eric Blake + stdlib: work around MirBSD WEXITSTATUS bug + * lib/stdlib.in.h (includes): Guarantee WEXITSTATUS. + * modules/stdlib (Depends-on): Add sys_wait. + * tests/test-sys_wait.c (main): Enhance test. + * tests/test-stdlib.c (main): Likewise. + * doc/posix-headers/stdlib.texi (stdlib.h): Document the bug. + docs: mention MacOS issue with WEXITSTATUS(constant) * doc/posix-headers/sys_wait.texi (sys/wait.h): Document the issue. diff --git a/doc/posix-headers/stdlib.texi b/doc/posix-headers/stdlib.texi index e1d6aba7d..f400f6274 100644 --- a/doc/posix-headers/stdlib.texi +++ b/doc/posix-headers/stdlib.texi @@ -17,6 +17,10 @@ The macro @code{EXIT_FAILURE} is incorrectly defined on Tandem/NSK. Some platforms provide a @code{NULL} macro that cannot be used in arbitrary expressions: NetBSD 5.0 + +@item +Some platforms fail to provide @code{WEXITSTATUS} and friends: +MirBSD 10. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index d4ac46903..0c1c16593 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -38,6 +38,11 @@ /* NetBSD 5.0 mis-defines NULL. */ #include +/* MirBSD 10 fails to define WEXITSTATUS. */ +#ifndef WEXITSTATUS +# include +#endif + /* Solaris declares getloadavg() in . */ #if (@GNULIB_GETLOADAVG@ || defined GNULIB_POSIXCHECK) && @HAVE_SYS_LOADAVG_H@ # include diff --git a/modules/stdlib b/modules/stdlib index 489f70a1a..f822aa3eb 100644 --- a/modules/stdlib +++ b/modules/stdlib @@ -11,6 +11,7 @@ c++defs include_next stddef stdint +sys_wait unistd warn-on-use diff --git a/tests/test-stdlib.c b/tests/test-stdlib.c index 4bd8715f3..8066b0525 100644 --- a/tests/test-stdlib.c +++ b/tests/test-stdlib.c @@ -22,7 +22,17 @@ #include "verify.h" -int exitcode; +/* Check that EXIT_SUCCESS is 0, per POSIX. */ +static int exitcode = EXIT_SUCCESS; +#if EXIT_SUCCESS +"oops" +#endif + +/* Check for GNU value (not guaranteed by POSIX, but is guaranteed by + gnulib). */ +#if EXIT_FAILURE != 1 +"oops" +#endif /* Check that NULL can be passed through varargs as a pointer type, per POSIX 2008. */ @@ -31,13 +41,23 @@ verify (sizeof NULL == sizeof (void *)); int main (void) { - /* Check that some macros are defined and different integer constants. */ - switch (exitcode) + /* Check subset of macros that must be visible here. + Note that some of these macros are only portable when operating + on an lvalue. */ + int i; + for (i = 0; i < 0x10000; i = (i ? i << 1 : 1)) + if (!!WIFSIGNALED (i) + !!WIFEXITED (i) + !!WIFSTOPPED (i) != 1) + return 1; + i = WEXITSTATUS (i) + WSTOPSIG (i) + WTERMSIG (i); + + switch (i) { - case EXIT_SUCCESS: - case EXIT_FAILURE: +#if 0 + /* Gnulib doesn't guarantee these, yet. */ + case WNOHANG: + case WUNTRACED: +#endif break; } - return 0; } diff --git a/tests/test-sys_wait.c b/tests/test-sys_wait.c index 8c0170ed9..917de0dc6 100644 --- a/tests/test-sys_wait.c +++ b/tests/test-sys_wait.c @@ -26,5 +26,26 @@ static pid_t a; int main (void) { - return a; + /* Check for existence of required macros. Note that we document + that these are safe only on lvalues. */ + int i; + for (i = 0; i < 0x10000; i = (i ? i << 1 : 1)) + if (!!WIFSIGNALED (i) + !!WIFEXITED (i) + !!WIFSTOPPED (i) != 1) + return 1; + i = WEXITSTATUS (i) + WSTOPSIG (i) + WTERMSIG (i); + + switch (i) + { +#if 0 + /* Gnulib doesn't guarantee these, yet. */ + case WCONTINUED: + case WNOHANG: + case WUNTRACED: + case WEXITED: + case WNOWAIT: + case WSTOPPED: +#endif + break; + } + return a ? i : 0; }