More linking issues fixed.
[glibc.git] / bits / waitstatus.h
blob699c22498947a4f9be0243d5dbf16eb253418a94
1 /* Definitions of status bits for `wait' et al.
2 Copyright (C) 1992,1994,1996,1997,2000,2004 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #if !defined _SYS_WAIT_H && !defined _STDLIB_H
21 # error "Never include <bits/waitstatus.h> directly; use <sys/wait.h> instead."
22 #endif
25 /* Everything extant so far uses these same bits. */
28 /* If WIFEXITED(STATUS), the low-order 8 bits of the status. */
29 #define __WEXITSTATUS(status) (((status) & 0xff00) >> 8)
31 /* If WIFSIGNALED(STATUS), the terminating signal. */
32 #define __WTERMSIG(status) ((status) & 0x7f)
34 /* If WIFSTOPPED(STATUS), the signal that stopped the child. */
35 #define __WSTOPSIG(status) __WEXITSTATUS(status)
37 /* Nonzero if STATUS indicates normal termination. */
38 #define __WIFEXITED(status) (__WTERMSIG(status) == 0)
40 /* Nonzero if STATUS indicates termination by a signal. */
41 #define __WIFSIGNALED(status) \
42 (((signed char) (((status) & 0x7f) + 1) >> 1) > 0)
44 /* Nonzero if STATUS indicates the child is stopped. */
45 #define __WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
47 /* Nonzero if STATUS indicates the child continued after a stop. We only
48 define this if <bits/waitflags.h> provides the WCONTINUED flag bit. */
49 #ifdef WCONTINUED
50 # define __WIFCONTINUED(status) ((status) == __W_CONTINUED)
51 #endif
53 /* Nonzero if STATUS indicates the child dumped core. */
54 #define __WCOREDUMP(status) ((status) & __WCOREFLAG)
56 /* Macros for constructing status values. */
57 #define __W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
58 #define __W_STOPCODE(sig) ((sig) << 8 | 0x7f)
59 #define __W_CONTINUED 0xffff
60 #define __WCOREFLAG 0x80
63 #ifdef __USE_BSD
65 # include <endian.h>
67 union wait
69 int w_status;
70 struct
72 # if __BYTE_ORDER == __LITTLE_ENDIAN
73 unsigned int __w_termsig:7; /* Terminating signal. */
74 unsigned int __w_coredump:1; /* Set if dumped core. */
75 unsigned int __w_retcode:8; /* Return code if exited normally. */
76 unsigned int:16;
77 # endif /* Little endian. */
78 # if __BYTE_ORDER == __BIG_ENDIAN
79 unsigned int:16;
80 unsigned int __w_retcode:8;
81 unsigned int __w_coredump:1;
82 unsigned int __w_termsig:7;
83 # endif /* Big endian. */
84 } __wait_terminated;
85 struct
87 # if __BYTE_ORDER == __LITTLE_ENDIAN
88 unsigned int __w_stopval:8; /* W_STOPPED if stopped. */
89 unsigned int __w_stopsig:8; /* Stopping signal. */
90 unsigned int:16;
91 # endif /* Little endian. */
92 # if __BYTE_ORDER == __BIG_ENDIAN
93 unsigned int:16;
94 unsigned int __w_stopsig:8; /* Stopping signal. */
95 unsigned int __w_stopval:8; /* W_STOPPED if stopped. */
96 # endif /* Big endian. */
97 } __wait_stopped;
100 # define w_termsig __wait_terminated.__w_termsig
101 # define w_coredump __wait_terminated.__w_coredump
102 # define w_retcode __wait_terminated.__w_retcode
103 # define w_stopsig __wait_stopped.__w_stopsig
104 # define w_stopval __wait_stopped.__w_stopval
106 #endif /* Use BSD. */