stdlib: work around MirBSD WEXITSTATUS bug
[gnulib.git] / tests / test-sys_wait.c
1 /* Test of <sys/wait.h> substitute.
2    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16
17 /* Written by Eric Blake <ebb9@byu.net>, 2009.  */
18
19 #include <config.h>
20
21 #include <sys/wait.h>
22
23 /* Check for existence of required types.  */
24 static pid_t a;
25
26 int
27 main (void)
28 {
29   /* Check for existence of required macros.  Note that we document
30      that these are safe only on lvalues.  */
31   int i;
32   for (i = 0; i < 0x10000; i = (i ? i << 1 : 1))
33     if (!!WIFSIGNALED (i) + !!WIFEXITED (i) + !!WIFSTOPPED (i) != 1)
34       return 1;
35   i = WEXITSTATUS (i) + WSTOPSIG (i) + WTERMSIG (i);
36
37   switch (i)
38     {
39 #if 0
40   /* Gnulib doesn't guarantee these, yet.  */
41     case WCONTINUED:
42     case WNOHANG:
43     case WUNTRACED:
44     case WEXITED:
45     case WNOWAIT:
46     case WSTOPPED:
47 #endif
48       break;
49     }
50   return a ? i : 0;
51 }