source: trunk/src/grep/gnulib-tests/test-sys_wait.h

Last change on this file was 3529, checked in by bird, 4 years ago

Imported grep 3.7 from grep-3.7.tar.gz (sha256: c22b0cf2d4f6bbe599c902387e8058990e1eee99aef333a203829e5fd3dbb342), applying minimal auto-props.

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1/* Test of macros shared between <sys/wait.h> and <stdlib.h>.
2 Copyright (C) 2010-2021 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 <https://www.gnu.org/licenses/>. */
16
17/* Written by Eric Blake <ebb9@byu.net>, 2010. */
18
19static int
20test_sys_wait_macros (void)
21{
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))
27 {
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;
40 }
41 i = WEXITSTATUS (i) + WSTOPSIG (i) + WTERMSIG (i);
42
43 switch (i)
44 {
45#if 0
46 /* Gnulib doesn't guarantee these, yet. */
47 case WNOHANG:
48 case WUNTRACED:
49#endif
50 break;
51 }
52 return 0;
53}
Note: See TracBrowser for help on using the repository browser.