xfreopen need not depend on freopen-safer
[gnulib.git] / lib / sys_wait.in.h
bloba4c52bb909e66645f7d0b3725e017abeacd8995e
1 /* A POSIX-like <sys/wait.h>.
2 Copyright (C) 2001-2003, 2005-2019 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 2, or (at your option)
7 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/>. */
18 #ifndef _@GUARD_PREFIX@_SYS_WAIT_H
20 #if __GNUC__ >= 3
21 @PRAGMA_SYSTEM_HEADER@
22 #endif
23 @PRAGMA_COLUMNS@
25 /* The include_next requires a split double-inclusion guard. */
26 #if !(defined _WIN32 && ! defined __CYGWIN__)
27 # @INCLUDE_NEXT@ @NEXT_SYS_WAIT_H@
28 #endif
30 #ifndef _@GUARD_PREFIX@_SYS_WAIT_H
31 #define _@GUARD_PREFIX@_SYS_WAIT_H
33 /* Get pid_t. */
34 #include <sys/types.h>
37 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
39 /* The definition of _GL_WARN_ON_USE is copied here. */
42 #if !(defined _WIN32 && ! defined __CYGWIN__)
43 /* Unix API. */
45 /* The following macros apply to an argument x, that is a status of a process,
46 as returned by waitpid().
47 On nearly all systems, including Linux/x86, WEXITSTATUS are bits 15..8 and
48 WTERMSIG are bits 7..0, while BeOS uses the opposite. Therefore programs
49 have to use the abstract macros. */
51 /* For valid x, exactly one of WIFSIGNALED(x), WIFEXITED(x), WIFSTOPPED(x)
52 is true. */
53 # ifndef WIFSIGNALED
54 # define WIFSIGNALED(x) (WTERMSIG (x) != 0 && WTERMSIG(x) != 0x7f)
55 # endif
56 # ifndef WIFEXITED
57 # define WIFEXITED(x) (WTERMSIG (x) == 0)
58 # endif
59 # ifndef WIFSTOPPED
60 # define WIFSTOPPED(x) (WTERMSIG (x) == 0x7f)
61 # endif
63 /* The termination signal. Only to be accessed if WIFSIGNALED(x) is true. */
64 # ifndef WTERMSIG
65 # define WTERMSIG(x) ((x) & 0x7f)
66 # endif
68 /* The exit status. Only to be accessed if WIFEXITED(x) is true. */
69 # ifndef WEXITSTATUS
70 # define WEXITSTATUS(x) (((x) >> 8) & 0xff)
71 # endif
73 /* The stopping signal. Only to be accessed if WIFSTOPPED(x) is true. */
74 # ifndef WSTOPSIG
75 # define WSTOPSIG(x) (((x) >> 8) & 0x7f)
76 # endif
78 /* True if the process dumped core. Not standardized by POSIX. */
79 # ifndef WCOREDUMP
80 # define WCOREDUMP(x) ((x) & 0x80)
81 # endif
83 #else
84 /* Native Windows API. */
86 # include <signal.h> /* for SIGTERM */
88 /* The following macros apply to an argument x, that is a status of a process,
89 as returned by waitpid() or, equivalently, _cwait() or GetExitCodeProcess().
90 This value is simply an 'int', not composed of bit fields. */
92 /* When an unhandled fatal signal terminates a process, the exit code is 3. */
93 # define WIFSIGNALED(x) ((x) == 3)
94 # define WIFEXITED(x) ((x) != 3)
95 # define WIFSTOPPED(x) 0
97 /* The signal that terminated a process is not known posthum. */
98 # define WTERMSIG(x) SIGTERM
100 # define WEXITSTATUS(x) (x)
102 /* There are no stopping signals. */
103 # define WSTOPSIG(x) 0
105 /* There are no core dumps. */
106 # define WCOREDUMP(x) 0
108 #endif
111 /* Declarations of functions. */
113 #if @GNULIB_WAITPID@
114 # if defined _WIN32 && ! defined __CYGWIN__
115 _GL_FUNCDECL_SYS (waitpid, pid_t, (pid_t pid, int *statusp, int options));
116 # endif
117 _GL_CXXALIAS_SYS (waitpid, pid_t, (pid_t pid, int *statusp, int options));
118 _GL_CXXALIASWARN (waitpid);
119 #elif defined GNULIB_POSIXCHECK
120 # undef waitpid
121 # if HAVE_RAW_DECL_WAITPID
122 _GL_WARN_ON_USE (waitpid, "waitpid is unportable - "
123 "use gnulib module sys_wait for portability");
124 # endif
125 #endif
128 #endif /* _@GUARD_PREFIX@_SYS_WAIT_H */
129 #endif /* _@GUARD_PREFIX@_SYS_WAIT_H */