Free backup buffer if one is available.
[glibc/history.git] / bits / waitstatus.h
blob1ec55107f98b9861798df05b3414eb9ed511aa9e
1 /* Definitions of status bits for `wait' et al.
2 Copyright (C) 1992, 1994, 1996, 1997 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #ifndef _SYS_WAIT_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 #ifdef __GNUC__
42 # define __WIFSIGNALED(status) \
43 (__extension__ ({ int __status = (status); \
44 !__WIFSTOPPED(__status) && !__WIFEXITED(__status); }))
45 #else /* Not GCC. */
46 # define __WIFSIGNALED(status) (!__WIFSTOPPED(status) && !__WIFEXITED(status))
47 #endif /* GCC. */
49 /* Nonzero if STATUS indicates the child is stopped. */
50 #define __WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
52 /* Nonzero if STATUS indicates the child dumped core. */
53 #define __WCOREDUMP(status) ((status) & __WCOREFLAG)
55 /* Macros for constructing status values. */
56 #define __W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
57 #define __W_STOPCODE(sig) ((sig) << 8 | 0x7f)
58 #define __WCOREFLAG 0x80
61 #ifdef __USE_BSD
63 # include <endian.h>
65 union wait
67 int w_status;
68 struct
70 # if __BYTE_ORDER == __LITTLE_ENDIAN
71 unsigned int __w_termsig:7; /* Terminating signal. */
72 unsigned int __w_coredump:1; /* Set if dumped core. */
73 unsigned int __w_retcode:8; /* Return code if exited normally. */
74 unsigned int:16;
75 # endif /* Little endian. */
76 # if __BYTE_ORDER == __BIG_ENDIAN
77 unsigned int:16;
78 unsigned int __w_retcode:8;
79 unsigned int __w_coredump:1;
80 unsigned int __w_termsig:7;
81 # endif /* Big endian. */
82 } __wait_terminated;
83 struct
85 # if __BYTE_ORDER == __LITTLE_ENDIAN
86 unsigned int __w_stopval:8; /* W_STOPPED if stopped. */
87 unsigned int __w_stopsig:8; /* Stopping signal. */
88 unsigned int:16;
89 # endif /* Little endian. */
90 # if __BYTE_ORDER == __BIG_ENDIAN
91 unsigned int:16;
92 unsigned int __w_stopsig:8; /* Stopping signal. */
93 unsigned int __w_stopval:8; /* W_STOPPED if stopped. */
94 # endif /* Big endian. */
95 } __wait_stopped;
98 # define w_termsig __wait_terminated.__w_termsig
99 # define w_coredump __wait_terminated.__w_coredump
100 # define w_retcode __wait_terminated.__w_retcode
101 # define w_stopsig __wait_stopped.__w_stopsig
102 # define w_stopval __wait_stopped.__w_stopval
104 #endif /* Use BSD. */