stdlib: work around MirBSD WEXITSTATUS bug
[gnulib.git] / tests / test-stdlib.c
index 4bd8715..8066b05 100644 (file)
 
 #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 <sys/wait.h> 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;
 }