update nearly all FSF copyright year lists to include 2009
[gnulib.git] / lib / sys_wait.in.h
1 /* A POSIX-like <sys/wait.h>.
2    Copyright (C) 2001-2003, 2005-2009 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 2, or (at your option)
7    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, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
18
19 #ifndef _GL_SYS_WAIT_H
20
21 #if __GNUC__ >= 3
22 @PRAGMA_SYSTEM_HEADER@
23 #endif
24
25 /* The include_next requires a split double-inclusion guard.  */
26 #if !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
27 # @INCLUDE_NEXT@ @NEXT_SYS_WAIT_H@
28 #endif
29
30 #ifndef _GL_SYS_WAIT_H
31 #define _GL_SYS_WAIT_H
32
33 /* The definition of GL_LINK_WARNING is copied here.  */
34
35 #if !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
36 /* Unix API.  */
37
38 /* The following macros apply to an argument x, that is a status of a process,
39    as returned by waitpid().
40    On nearly all systems, including Linux/x86, WEXITSTATUS are bits 15..8 and
41    WTERMSIG are bits 7..0, while BeOS uses the opposite.  Therefore programs
42    have to use the abstract macros.  */
43
44 /* For valid x, exactly one of WIFSIGNALED(x), WIFEXITED(x), WIFSTOPPED(x)
45    is true.  */
46 # ifndef WIFSIGNALED
47 #  define WIFSIGNALED(x) (WTERMSIG (x) != 0 && WTERMSIG(x) != 0x7f)
48 # endif
49 # ifndef WIFEXITED
50 #  define WIFEXITED(x) (WTERMSIG (x) == 0)
51 # endif
52 # ifndef WIFSTOPPED
53 #  define WIFSTOPPED(x) (WTERMSIG (x) == 0x7f)
54 # endif
55
56 /* The termination signal. Only to be accessed if WIFSIGNALED(x) is true.  */
57 # ifndef WTERMSIG
58 #  define WTERMSIG(x) ((x) & 0x7f)
59 # endif
60
61 /* The exit status. Only to be accessed if WIFEXITED(x) is true.  */
62 # ifndef WEXITSTATUS
63 #  define WEXITSTATUS(x) (((x) >> 8) & 0xff)
64 # endif
65
66 /* True if the process dumped core.  Not standardized by POSIX.  */
67 # ifndef WCOREDUMP
68 #  define WCOREDUMP(x) ((x) & 0x80)
69 # endif
70
71 # ifdef __cplusplus
72 extern "C" {
73 # endif
74
75 /* Declarations of functions.  */
76
77 # ifdef __cplusplus
78 }
79 # endif
80
81 #else
82 /* Native Windows API.  */
83
84 # include <process.h>
85
86 # define waitpid(pid,statusp,options) _cwait (statusp, pid, WAIT_CHILD)
87
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.  */
91
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
96
97 /* The signal that terminated a process is not known posthum.  */
98 # define WTERMSIG(x) SIGTERM
99
100 # define WEXITSTATUS(x) (x)
101
102 /* There are no core dumps.  */
103 # define WCOREDUMP(x) 0
104
105 #endif
106
107 #endif /* _GL_SYS_WAIT_H */
108 #endif /* _GL_SYS_WAIT_H */