1*4b169a6bSchristos /* A POSIX-like <sys/wait.h>. 2*4b169a6bSchristos Copyright (C) 2001-2003, 2005-2022 Free Software Foundation, Inc. 3*4b169a6bSchristos 4*4b169a6bSchristos This file is free software: you can redistribute it and/or modify 5*4b169a6bSchristos it under the terms of the GNU Lesser General Public License as 6*4b169a6bSchristos published by the Free Software Foundation; either version 2.1 of the 7*4b169a6bSchristos License, or (at your option) any later version. 8*4b169a6bSchristos 9*4b169a6bSchristos This file is distributed in the hope that it will be useful, 10*4b169a6bSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 11*4b169a6bSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*4b169a6bSchristos GNU Lesser General Public License for more details. 13*4b169a6bSchristos 14*4b169a6bSchristos You should have received a copy of the GNU Lesser General Public License 15*4b169a6bSchristos along with this program. If not, see <https://www.gnu.org/licenses/>. */ 16*4b169a6bSchristos 17*4b169a6bSchristos 18*4b169a6bSchristos #ifndef _@GUARD_PREFIX@_SYS_WAIT_H 19*4b169a6bSchristos 20*4b169a6bSchristos #if __GNUC__ >= 3 21*4b169a6bSchristos @PRAGMA_SYSTEM_HEADER@ 22*4b169a6bSchristos #endif 23*4b169a6bSchristos @PRAGMA_COLUMNS@ 24*4b169a6bSchristos 25*4b169a6bSchristos /* The include_next requires a split double-inclusion guard. */ 26*4b169a6bSchristos #if !(defined _WIN32 && ! defined __CYGWIN__) 27*4b169a6bSchristos # @INCLUDE_NEXT@ @NEXT_SYS_WAIT_H@ 28*4b169a6bSchristos #endif 29*4b169a6bSchristos 30*4b169a6bSchristos #ifndef _@GUARD_PREFIX@_SYS_WAIT_H 31*4b169a6bSchristos #define _@GUARD_PREFIX@_SYS_WAIT_H 32*4b169a6bSchristos 33*4b169a6bSchristos /* Get pid_t. */ 34*4b169a6bSchristos #include <sys/types.h> 35*4b169a6bSchristos 36*4b169a6bSchristos 37*4b169a6bSchristos /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 38*4b169a6bSchristos 39*4b169a6bSchristos /* The definition of _GL_WARN_ON_USE is copied here. */ 40*4b169a6bSchristos 41*4b169a6bSchristos 42*4b169a6bSchristos #if !(defined _WIN32 && ! defined __CYGWIN__) 43*4b169a6bSchristos /* Unix API. */ 44*4b169a6bSchristos 45*4b169a6bSchristos /* The following macros apply to an argument x, that is a status of a process, 46*4b169a6bSchristos as returned by waitpid(). 47*4b169a6bSchristos On nearly all systems, including Linux/x86, WEXITSTATUS are bits 15..8 and 48*4b169a6bSchristos WTERMSIG are bits 7..0, while BeOS uses the opposite. Therefore programs 49*4b169a6bSchristos have to use the abstract macros. */ 50*4b169a6bSchristos 51*4b169a6bSchristos /* For valid x, exactly one of WIFSIGNALED(x), WIFEXITED(x), WIFSTOPPED(x) 52*4b169a6bSchristos is true. */ 53*4b169a6bSchristos # ifndef WIFSIGNALED 54*4b169a6bSchristos # define WIFSIGNALED(x) (WTERMSIG (x) != 0 && WTERMSIG(x) != 0x7f) 55*4b169a6bSchristos # endif 56*4b169a6bSchristos # ifndef WIFEXITED 57*4b169a6bSchristos # define WIFEXITED(x) (WTERMSIG (x) == 0) 58*4b169a6bSchristos # endif 59*4b169a6bSchristos # ifndef WIFSTOPPED 60*4b169a6bSchristos # define WIFSTOPPED(x) (WTERMSIG (x) == 0x7f) 61*4b169a6bSchristos # endif 62*4b169a6bSchristos 63*4b169a6bSchristos /* The termination signal. Only to be accessed if WIFSIGNALED(x) is true. */ 64*4b169a6bSchristos # ifndef WTERMSIG 65*4b169a6bSchristos # define WTERMSIG(x) ((x) & 0x7f) 66*4b169a6bSchristos # endif 67*4b169a6bSchristos 68*4b169a6bSchristos /* The exit status. Only to be accessed if WIFEXITED(x) is true. */ 69*4b169a6bSchristos # ifndef WEXITSTATUS 70*4b169a6bSchristos # define WEXITSTATUS(x) (((x) >> 8) & 0xff) 71*4b169a6bSchristos # endif 72*4b169a6bSchristos 73*4b169a6bSchristos /* The stopping signal. Only to be accessed if WIFSTOPPED(x) is true. */ 74*4b169a6bSchristos # ifndef WSTOPSIG 75*4b169a6bSchristos # define WSTOPSIG(x) (((x) >> 8) & 0x7f) 76*4b169a6bSchristos # endif 77*4b169a6bSchristos 78*4b169a6bSchristos /* True if the process dumped core. Not standardized by POSIX. */ 79*4b169a6bSchristos # ifndef WCOREDUMP 80*4b169a6bSchristos # define WCOREDUMP(x) ((x) & 0x80) 81*4b169a6bSchristos # endif 82*4b169a6bSchristos 83*4b169a6bSchristos #else 84*4b169a6bSchristos /* Native Windows API. */ 85*4b169a6bSchristos 86*4b169a6bSchristos # include <signal.h> /* for SIGTERM */ 87*4b169a6bSchristos 88*4b169a6bSchristos /* The following macros apply to an argument x, that is a status of a process, 89*4b169a6bSchristos as returned by waitpid() or, equivalently, _cwait() or GetExitCodeProcess(). 90*4b169a6bSchristos This value is simply an 'int', not composed of bit fields. */ 91*4b169a6bSchristos 92*4b169a6bSchristos /* When an unhandled fatal signal terminates a process, the exit code is 3. */ 93*4b169a6bSchristos # define WIFSIGNALED(x) ((x) == 3) 94*4b169a6bSchristos # define WIFEXITED(x) ((x) != 3) 95*4b169a6bSchristos # define WIFSTOPPED(x) 0 96*4b169a6bSchristos 97*4b169a6bSchristos /* The signal that terminated a process is not known posthum. */ 98*4b169a6bSchristos # define WTERMSIG(x) SIGTERM 99*4b169a6bSchristos 100*4b169a6bSchristos # define WEXITSTATUS(x) (x) 101*4b169a6bSchristos 102*4b169a6bSchristos /* There are no stopping signals. */ 103*4b169a6bSchristos # define WSTOPSIG(x) 0 104*4b169a6bSchristos 105*4b169a6bSchristos /* There are no core dumps. */ 106*4b169a6bSchristos # define WCOREDUMP(x) 0 107*4b169a6bSchristos 108*4b169a6bSchristos #endif 109*4b169a6bSchristos 110*4b169a6bSchristos 111*4b169a6bSchristos /* Declarations of functions. */ 112*4b169a6bSchristos 113*4b169a6bSchristos #if @GNULIB_WAITPID@ 114*4b169a6bSchristos # if defined _WIN32 && ! defined __CYGWIN__ 115*4b169a6bSchristos _GL_FUNCDECL_SYS (waitpid, pid_t, (pid_t pid, int *statusp, int options)); 116*4b169a6bSchristos # endif 117*4b169a6bSchristos /* Need to cast, because on Cygwin, the second parameter is 118*4b169a6bSchristos __wait_status_ptr_t statusp. */ 119*4b169a6bSchristos _GL_CXXALIAS_SYS_CAST (waitpid, pid_t, (pid_t pid, int *statusp, int options)); 120*4b169a6bSchristos _GL_CXXALIASWARN (waitpid); 121*4b169a6bSchristos #elif defined GNULIB_POSIXCHECK 122*4b169a6bSchristos # undef waitpid 123*4b169a6bSchristos # if HAVE_RAW_DECL_WAITPID 124*4b169a6bSchristos _GL_WARN_ON_USE (waitpid, "waitpid is unportable - " 125*4b169a6bSchristos "use gnulib module sys_wait for portability"); 126*4b169a6bSchristos # endif 127*4b169a6bSchristos #endif 128*4b169a6bSchristos 129*4b169a6bSchristos 130*4b169a6bSchristos #endif /* _@GUARD_PREFIX@_SYS_WAIT_H */ 131*4b169a6bSchristos #endif /* _@GUARD_PREFIX@_SYS_WAIT_H */ 132