openat: don’t close (-1)
[gnulib.git] / tests / test-sys_wait.h
blob5f2eec5493678316fc263131b2ac81834eaa3792
1 /* Test of macros shared between <sys/wait.h> and <stdlib.h>.
2 Copyright (C) 2010-2024 Free Software Foundation, Inc.
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Eric Blake <ebb9@byu.net>, 2010. */
19 static int
20 test_sys_wait_macros (void)
22 /* Check subset of <sys/wait.h> macros that must be visible here.
23 Note that some of these macros are only portable when operating
24 on an lvalue. */
25 int i;
26 for (i = 0; i < 0x8000; i = (i ? i << 1 : 1))
28 /* POSIX requires that for all valid process statuses, that
29 exactly one of these three macros is true. But not all
30 possible 16-bit values map to valid process status.
31 Traditionally, 8 of the bits are for WIFEXITED, 7 of the bits
32 to tell between WIFSIGNALED and WIFSTOPPED, and either 0x80
33 or 0x8000 to flag that core was also dumped. Since we don't
34 know which byte is WIFEXITED, we skip the both possible bits
35 that can signal core dump. */
36 if (i == 0x80)
37 continue;
38 if (!!WIFSIGNALED (i) + !!WIFEXITED (i) + !!WIFSTOPPED (i) != 1)
39 return 1;
41 i = WEXITSTATUS (i) + WSTOPSIG (i) + WTERMSIG (i);
43 #if 0
44 switch (i)
46 /* Gnulib doesn't guarantee these, yet. */
47 case WNOHANG:
48 case WUNTRACED:
49 break;
51 #endif
52 return 0;