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