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