Back to index

glibc  2.9
waitstatus.h
Go to the documentation of this file.
00001 /* Definitions of status bits for `wait' et al.
00002    Copyright (C) 1992,1994,1996,1997,2000,2004 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #if !defined _SYS_WAIT_H && !defined _STDLIB_H
00021 # error "Never include <bits/waitstatus.h> directly; use <sys/wait.h> instead."
00022 #endif
00023 
00024 
00025 /* Everything extant so far uses these same bits.  */
00026 
00027 
00028 /* If WIFEXITED(STATUS), the low-order 8 bits of the status.  */
00029 #define       __WEXITSTATUS(status)       (((status) & 0xff00) >> 8)
00030 
00031 /* If WIFSIGNALED(STATUS), the terminating signal.  */
00032 #define       __WTERMSIG(status)   ((status) & 0x7f)
00033 
00034 /* If WIFSTOPPED(STATUS), the signal that stopped the child.  */
00035 #define       __WSTOPSIG(status)   __WEXITSTATUS(status)
00036 
00037 /* Nonzero if STATUS indicates normal termination.  */
00038 #define       __WIFEXITED(status)  (__WTERMSIG(status) == 0)
00039 
00040 /* Nonzero if STATUS indicates termination by a signal.  */
00041 #define __WIFSIGNALED(status) \
00042   (((signed char) (((status) & 0x7f) + 1) >> 1) > 0)
00043 
00044 /* Nonzero if STATUS indicates the child is stopped.  */
00045 #define       __WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
00046 
00047 /* Nonzero if STATUS indicates the child continued after a stop.  We only
00048    define this if <bits/waitflags.h> provides the WCONTINUED flag bit.  */
00049 #ifdef WCONTINUED
00050 # define __WIFCONTINUED(status)    ((status) == __W_CONTINUED)
00051 #endif
00052 
00053 /* Nonzero if STATUS indicates the child dumped core.  */
00054 #define       __WCOREDUMP(status)  ((status) & __WCOREFLAG)
00055 
00056 /* Macros for constructing status values.  */
00057 #define       __W_EXITCODE(ret, sig)      ((ret) << 8 | (sig))
00058 #define       __W_STOPCODE(sig)    ((sig) << 8 | 0x7f)
00059 #define __W_CONTINUED              0xffff
00060 #define       __WCOREFLAG          0x80
00061 
00062 
00063 #ifdef __USE_BSD
00064 
00065 # include <endian.h>
00066 
00067 union wait
00068   {
00069     int w_status;
00070     struct
00071       {
00072 # if   __BYTE_ORDER == __LITTLE_ENDIAN
00073        unsigned int __w_termsig:7; /* Terminating signal.  */
00074        unsigned int __w_coredump:1; /* Set if dumped core.  */
00075        unsigned int __w_retcode:8; /* Return code if exited normally.  */
00076        unsigned int:16;
00077 # endif                            /* Little endian.  */
00078 # if   __BYTE_ORDER == __BIG_ENDIAN
00079        unsigned int:16;
00080        unsigned int __w_retcode:8;
00081        unsigned int __w_coredump:1;
00082        unsigned int __w_termsig:7;
00083 # endif                            /* Big endian.  */
00084       } __wait_terminated;
00085     struct
00086       {
00087 # if   __BYTE_ORDER == __LITTLE_ENDIAN
00088        unsigned int __w_stopval:8; /* W_STOPPED if stopped.  */
00089        unsigned int __w_stopsig:8; /* Stopping signal.  */
00090        unsigned int:16;
00091 # endif                            /* Little endian.  */
00092 # if   __BYTE_ORDER == __BIG_ENDIAN
00093        unsigned int:16;
00094        unsigned int __w_stopsig:8; /* Stopping signal.  */
00095        unsigned int __w_stopval:8; /* W_STOPPED if stopped.  */
00096 # endif                            /* Big endian.  */
00097       } __wait_stopped;
00098   };
00099 
00100 # define w_termsig   __wait_terminated.__w_termsig
00101 # define w_coredump  __wait_terminated.__w_coredump
00102 # define w_retcode   __wait_terminated.__w_retcode
00103 # define w_stopsig   __wait_stopped.__w_stopsig
00104 # define w_stopval   __wait_stopped.__w_stopval
00105 
00106 #endif /* Use BSD.  */