Clang Project

include/x86_64-linux-gnu/bits/waitstatus.h
1/* Definitions of status bits for `wait' et al.
2   Copyright (C) 1992-2016 Free Software Foundation, Inc.
3   This file is part of the GNU C Library.
4
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.
9
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.
14
15   You should have received a copy of the GNU Lesser General Public
16   License along with the GNU C Library; if not, see
17   <http://www.gnu.org/licenses/>.  */
18
19#if !defined _SYS_WAIT_H && !defined _STDLIB_H
20# error "Never include <bits/waitstatus.h> directly; use <sys/wait.h> instead."
21#endif
22
23
24/* Everything extant so far uses these same bits.  */
25
26
27/* If WIFEXITED(STATUS), the low-order 8 bits of the status.  */
28#define __WEXITSTATUS(status) (((status) & 0xff00) >> 8)
29
30/* If WIFSIGNALED(STATUS), the terminating signal.  */
31#define __WTERMSIG(status) ((status) & 0x7f)
32
33/* If WIFSTOPPED(STATUS), the signal that stopped the child.  */
34#define __WSTOPSIG(status) __WEXITSTATUS(status)
35
36/* Nonzero if STATUS indicates normal termination.  */
37#define __WIFEXITED(status) (__WTERMSIG(status) == 0)
38
39/* Nonzero if STATUS indicates termination by a signal.  */
40#define __WIFSIGNALED(status) \
41  (((signed char) (((status) & 0x7f) + 1) >> 1) > 0)
42
43/* Nonzero if STATUS indicates the child is stopped.  */
44#define __WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
45
46/* Nonzero if STATUS indicates the child continued after a stop.  We only
47   define this if <bits/waitflags.h> provides the WCONTINUED flag bit.  */
48#ifdef WCONTINUED
49define __WIFCONTINUED(status) ((status) == __W_CONTINUED)
50#endif
51
52/* Nonzero if STATUS indicates the child dumped core.  */
53#define __WCOREDUMP(status) ((status) & __WCOREFLAG)
54
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 __W_CONTINUED 0xffff
59#define __WCOREFLAG 0x80
60
61
62#ifdef __USE_MISC
63
64include <endian.h>
65
66union wait
67  {
68    int w_status;
69    struct
70      {
71if __BYTE_ORDER == __LITTLE_ENDIAN
72 unsigned int __w_termsig:7/* Terminating signal.  */
73 unsigned int __w_coredump:1/* Set if dumped core.  */
74 unsigned int __w_retcode:8/* Return code if exited normally.  */
75 unsigned int:16;
76endif /* Little endian.  */
77if __BYTE_ORDER == __BIG_ENDIAN
78 unsigned int:16;
79 unsigned int __w_retcode:8;
80 unsigned int __w_coredump:1;
81 unsigned int __w_termsig:7;
82endif /* Big endian.  */
83      } __wait_terminated;
84    struct
85      {
86if __BYTE_ORDER == __LITTLE_ENDIAN
87 unsigned int __w_stopval:8/* W_STOPPED if stopped.  */
88 unsigned int __w_stopsig:8/* Stopping signal.  */
89 unsigned int:16;
90endif /* Little endian.  */
91if __BYTE_ORDER == __BIG_ENDIAN
92 unsigned int:16;
93 unsigned int __w_stopsig:8/* Stopping signal.  */
94 unsigned int __w_stopval:8/* W_STOPPED if stopped.  */
95endif /* Big endian.  */
96      } __wait_stopped;
97  };
98
99define w_termsig __wait_terminated.__w_termsig
100define w_coredump __wait_terminated.__w_coredump
101define w_retcode __wait_terminated.__w_retcode
102define w_stopsig __wait_stopped.__w_stopsig
103define w_stopval __wait_stopped.__w_stopval
104
105#endif /* Use misc.  */
106
wait::w_status
wait::(anonymous struct)::__w_termsig
wait::(anonymous struct)::__w_coredump
wait::(anonymous struct)::__w_retcode
wait::__wait_terminated
wait::(anonymous struct)::__w_stopval
wait::(anonymous struct)::__w_stopsig
wait::__wait_stopped