1 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
2 /* A POSIX-like <sys/wait.h>.
3 Copyright (C) 2001-2003, 2005-2019 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3, or (at your option)
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <https://www.gnu.org/licenses/>. */
19 #ifndef _GL_SYS_WAIT_H
22 #pragma GCC system_header
26 /* The include_next requires a split double-inclusion guard. */
27 #if !(defined _WIN32 && ! defined __CYGWIN__)
28 # include_next <sys/wait.h>
31 #ifndef _GL_SYS_WAIT_H
32 #define _GL_SYS_WAIT_H
35 #include <sys/types.h>
38 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
39 /* C++ compatible function declaration macros.
40 Copyright (C) 2010-2019 Free Software Foundation, Inc.
42 This program is free software: you can redistribute it and/or modify it
43 under the terms of the GNU General Public License as published
44 by the Free Software Foundation; either version 3 of the License, or
45 (at your option) any later version.
47 This program is distributed in the hope that it will be useful,
48 but WITHOUT ANY WARRANTY; without even the implied warranty of
49 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
50 General Public License for more details.
52 You should have received a copy of the GNU General Public License
53 along with this program. If not, see <https://www.gnu.org/licenses/>. */
58 /* Begin/end the GNULIB_NAMESPACE namespace. */
59 #if defined __cplusplus && defined GNULIB_NAMESPACE
60 # define _GL_BEGIN_NAMESPACE namespace GNULIB_NAMESPACE {
61 # define _GL_END_NAMESPACE }
63 # define _GL_BEGIN_NAMESPACE
64 # define _GL_END_NAMESPACE
67 /* The three most frequent use cases of these macros are:
69 * For providing a substitute for a function that is missing on some
70 platforms, but is declared and works fine on the platforms on which
75 _GL_FUNCDECL_SYS (foo, ...);
77 _GL_CXXALIAS_SYS (foo, ...);
78 _GL_CXXALIASWARN (foo);
79 #elif defined GNULIB_POSIXCHECK
83 * For providing a replacement for a function that exists on all platforms,
84 but is broken/insufficient and needs to be replaced on some platforms:
88 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
92 _GL_FUNCDECL_RPL (foo, ...);
93 _GL_CXXALIAS_RPL (foo, ...);
95 _GL_CXXALIAS_SYS (foo, ...);
97 _GL_CXXALIASWARN (foo);
98 #elif defined GNULIB_POSIXCHECK
102 * For providing a replacement for a function that exists on some platforms
103 but is broken/insufficient and needs to be replaced on some of them and
104 is additionally either missing or undeclared on some other platforms:
108 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
112 _GL_FUNCDECL_RPL (foo, ...);
113 _GL_CXXALIAS_RPL (foo, ...);
115 # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
116 _GL_FUNCDECL_SYS (foo, ...);
118 _GL_CXXALIAS_SYS (foo, ...);
120 _GL_CXXALIASWARN (foo);
121 #elif defined GNULIB_POSIXCHECK
126 /* _GL_EXTERN_C declaration;
127 performs the declaration with C linkage. */
128 #if defined __cplusplus
129 # define _GL_EXTERN_C extern "C"
131 # define _GL_EXTERN_C extern
134 /* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
135 declares a replacement function, named rpl_func, with the given prototype,
136 consisting of return type, parameters, and attributes.
138 _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
139 _GL_ARG_NONNULL ((1)));
141 #define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
142 _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
143 #define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
144 _GL_EXTERN_C rettype rpl_func parameters_and_attributes
146 /* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
147 declares the system function, named func, with the given prototype,
148 consisting of return type, parameters, and attributes.
150 _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
151 _GL_ARG_NONNULL ((1)));
153 #define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
154 _GL_EXTERN_C rettype func parameters_and_attributes
156 /* _GL_CXXALIAS_RPL (func, rettype, parameters);
157 declares a C++ alias called GNULIB_NAMESPACE::func
158 that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
160 _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
162 Wrapping rpl_func in an object with an inline conversion operator
163 avoids a reference to rpl_func unless GNULIB_NAMESPACE::func is
164 actually used in the program. */
165 #define _GL_CXXALIAS_RPL(func,rettype,parameters) \
166 _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
167 #if defined __cplusplus && defined GNULIB_NAMESPACE
168 # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
169 namespace GNULIB_NAMESPACE \
171 static const struct _gl_ ## func ## _wrapper \
173 typedef rettype (*type) parameters; \
175 inline operator type () const \
181 _GL_EXTERN_C int _gl_cxxalias_dummy
183 # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
184 _GL_EXTERN_C int _gl_cxxalias_dummy
187 /* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
188 is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
189 except that the C function rpl_func may have a slightly different
190 declaration. A cast is used to silence the "invalid conversion" error
191 that would otherwise occur. */
192 #if defined __cplusplus && defined GNULIB_NAMESPACE
193 # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
194 namespace GNULIB_NAMESPACE \
196 static const struct _gl_ ## func ## _wrapper \
198 typedef rettype (*type) parameters; \
200 inline operator type () const \
202 return reinterpret_cast<type>(::rpl_func); \
206 _GL_EXTERN_C int _gl_cxxalias_dummy
208 # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
209 _GL_EXTERN_C int _gl_cxxalias_dummy
212 /* _GL_CXXALIAS_SYS (func, rettype, parameters);
213 declares a C++ alias called GNULIB_NAMESPACE::func
214 that redirects to the system provided function func, if GNULIB_NAMESPACE
217 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
219 Wrapping func in an object with an inline conversion operator
220 avoids a reference to func unless GNULIB_NAMESPACE::func is
221 actually used in the program. */
222 #if defined __cplusplus && defined GNULIB_NAMESPACE
223 # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
224 namespace GNULIB_NAMESPACE \
226 static const struct _gl_ ## func ## _wrapper \
228 typedef rettype (*type) parameters; \
230 inline operator type () const \
236 _GL_EXTERN_C int _gl_cxxalias_dummy
238 # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
239 _GL_EXTERN_C int _gl_cxxalias_dummy
242 /* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
243 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
244 except that the C function func may have a slightly different declaration.
245 A cast is used to silence the "invalid conversion" error that would
247 #if defined __cplusplus && defined GNULIB_NAMESPACE
248 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
249 namespace GNULIB_NAMESPACE \
251 static const struct _gl_ ## func ## _wrapper \
253 typedef rettype (*type) parameters; \
255 inline operator type () const \
257 return reinterpret_cast<type>(::func); \
261 _GL_EXTERN_C int _gl_cxxalias_dummy
263 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
264 _GL_EXTERN_C int _gl_cxxalias_dummy
267 /* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
268 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
269 except that the C function is picked among a set of overloaded functions,
270 namely the one with rettype2 and parameters2. Two consecutive casts
271 are used to silence the "cannot find a match" and "invalid conversion"
272 errors that would otherwise occur. */
273 #if defined __cplusplus && defined GNULIB_NAMESPACE
274 /* The outer cast must be a reinterpret_cast.
275 The inner cast: When the function is defined as a set of overloaded
276 functions, it works as a static_cast<>, choosing the designated variant.
277 When the function is defined as a single variant, it works as a
278 reinterpret_cast<>. The parenthesized cast syntax works both ways. */
279 # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
280 namespace GNULIB_NAMESPACE \
282 static const struct _gl_ ## func ## _wrapper \
284 typedef rettype (*type) parameters; \
286 inline operator type () const \
288 return reinterpret_cast<type>((rettype2 (*) parameters2)(::func)); \
292 _GL_EXTERN_C int _gl_cxxalias_dummy
294 # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
295 _GL_EXTERN_C int _gl_cxxalias_dummy
298 /* _GL_CXXALIASWARN (func);
299 causes a warning to be emitted when ::func is used but not when
300 GNULIB_NAMESPACE::func is used. func must be defined without overloaded
302 #if defined __cplusplus && defined GNULIB_NAMESPACE
303 # define _GL_CXXALIASWARN(func) \
304 _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
305 # define _GL_CXXALIASWARN_1(func,namespace) \
306 _GL_CXXALIASWARN_2 (func, namespace)
307 /* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
308 we enable the warning only when not optimizing. */
310 # define _GL_CXXALIASWARN_2(func,namespace) \
311 _GL_WARN_ON_USE (func, \
312 "The symbol ::" #func " refers to the system function. " \
313 "Use " #namespace "::" #func " instead.")
314 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
315 # define _GL_CXXALIASWARN_2(func,namespace) \
316 extern __typeof__ (func) func
318 # define _GL_CXXALIASWARN_2(func,namespace) \
319 _GL_EXTERN_C int _gl_cxxalias_dummy
322 # define _GL_CXXALIASWARN(func) \
323 _GL_EXTERN_C int _gl_cxxalias_dummy
326 /* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
327 causes a warning to be emitted when the given overloaded variant of ::func
328 is used but not when GNULIB_NAMESPACE::func is used. */
329 #if defined __cplusplus && defined GNULIB_NAMESPACE
330 # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
331 _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
333 # define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
334 _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
335 /* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
336 we enable the warning only when not optimizing. */
338 # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
339 _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
340 "The symbol ::" #func " refers to the system function. " \
341 "Use " #namespace "::" #func " instead.")
342 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
343 # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
344 extern __typeof__ (func) func
346 # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
347 _GL_EXTERN_C int _gl_cxxalias_dummy
350 # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
351 _GL_EXTERN_C int _gl_cxxalias_dummy
354 #endif /* _GL_CXXDEFS_H */
356 /* The definition of _GL_WARN_ON_USE is copied here. */
357 /* A C macro for emitting warnings if a function is used.
358 Copyright (C) 2010-2019 Free Software Foundation, Inc.
360 This program is free software: you can redistribute it and/or modify it
361 under the terms of the GNU General Public License as published
362 by the Free Software Foundation; either version 3 of the License, or
363 (at your option) any later version.
365 This program is distributed in the hope that it will be useful,
366 but WITHOUT ANY WARRANTY; without even the implied warranty of
367 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
368 General Public License for more details.
370 You should have received a copy of the GNU General Public License
371 along with this program. If not, see <https://www.gnu.org/licenses/>. */
373 /* _GL_WARN_ON_USE (function, "literal string") issues a declaration
374 for FUNCTION which will then trigger a compiler warning containing
375 the text of "literal string" anywhere that function is called, if
376 supported by the compiler. If the compiler does not support this
377 feature, the macro expands to an unused extern declaration.
379 _GL_WARN_ON_USE_ATTRIBUTE ("literal string") expands to the
380 attribute used in _GL_WARN_ON_USE. If the compiler does not support
381 this feature, it expands to empty.
383 These macros are useful for marking a function as a potential
384 portability trap, with the intent that "literal string" include
385 instructions on the replacement function that should be used
387 _GL_WARN_ON_USE is for functions with 'extern' linkage.
388 _GL_WARN_ON_USE_ATTRIBUTE is for functions with 'static' or 'inline'
391 However, one of the reasons that a function is a portability trap is
392 if it has the wrong signature. Declaring FUNCTION with a different
393 signature in C is a compilation error, so this macro must use the
394 same type as any existing declaration so that programs that avoid
395 the problematic FUNCTION do not fail to compile merely because they
396 included a header that poisoned the function. But this implies that
397 _GL_WARN_ON_USE is only safe to use if FUNCTION is known to already
398 have a declaration. Use of this macro implies that there must not
399 be any other macro hiding the declaration of FUNCTION; but
400 undefining FUNCTION first is part of the poisoning process anyway
401 (although for symbols that are provided only via a macro, the result
402 is a compilation error rather than a warning containing
403 "literal string"). Also note that in C++, it is only safe to use if
404 FUNCTION has no overloads.
406 For an example, it is possible to poison 'getline' by:
407 - adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]],
408 [getline]) in configure.ac, which potentially defines
409 HAVE_RAW_DECL_GETLINE
410 - adding this code to a header that wraps the system <stdio.h>:
412 #if HAVE_RAW_DECL_GETLINE
413 _GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but"
414 "not universally present; use the gnulib module getline");
417 It is not possible to directly poison global variables. But it is
418 possible to write a wrapper accessor function, and poison that
419 (less common usage, like &environ, will cause a compilation error
420 rather than issue the nice warning, but the end result of informing
421 the developer about their portability problem is still achieved):
422 #if HAVE_RAW_DECL_ENVIRON
424 rpl_environ (void) { return &environ; }
425 _GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared");
427 # define environ (*rpl_environ ())
429 or better (avoiding contradictory use of 'static' and 'extern'):
430 #if HAVE_RAW_DECL_ENVIRON
432 _GL_WARN_ON_USE_ATTRIBUTE ("environ is not always properly declared")
433 rpl_environ (void) { return &environ; }
435 # define environ (*rpl_environ ())
438 #ifndef _GL_WARN_ON_USE
440 # if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
441 /* A compiler attribute is available in gcc versions 4.3.0 and later. */
442 # define _GL_WARN_ON_USE(function, message) \
443 extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
444 # define _GL_WARN_ON_USE_ATTRIBUTE(message) \
445 __attribute__ ((__warning__ (message)))
446 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
447 /* Verify the existence of the function. */
448 # define _GL_WARN_ON_USE(function, message) \
449 extern __typeof__ (function) function
450 # define _GL_WARN_ON_USE_ATTRIBUTE(message)
451 # else /* Unsupported. */
452 # define _GL_WARN_ON_USE(function, message) \
453 _GL_WARN_EXTERN_C int _gl_warn_on_use
454 # define _GL_WARN_ON_USE_ATTRIBUTE(message)
458 /* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
459 is like _GL_WARN_ON_USE (function, "string"), except that the function is
460 declared with the given prototype, consisting of return type, parameters,
462 This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
463 not work in this case. */
464 #ifndef _GL_WARN_ON_USE_CXX
465 # if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
466 # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
467 extern rettype function parameters_and_attributes \
468 __attribute__ ((__warning__ (msg)))
469 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
470 /* Verify the existence of the function. */
471 # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
472 extern rettype function parameters_and_attributes
473 # else /* Unsupported. */
474 # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
475 _GL_WARN_EXTERN_C int _gl_warn_on_use
479 /* _GL_WARN_EXTERN_C declaration;
480 performs the declaration with C linkage. */
481 #ifndef _GL_WARN_EXTERN_C
482 # if defined __cplusplus
483 # define _GL_WARN_EXTERN_C extern "C"
485 # define _GL_WARN_EXTERN_C extern
490 #if !(defined _WIN32 && ! defined __CYGWIN__)
493 /* The following macros apply to an argument x, that is a status of a process,
494 as returned by waitpid().
495 On nearly all systems, including Linux/x86, WEXITSTATUS are bits 15..8 and
496 WTERMSIG are bits 7..0, while BeOS uses the opposite. Therefore programs
497 have to use the abstract macros. */
499 /* For valid x, exactly one of WIFSIGNALED(x), WIFEXITED(x), WIFSTOPPED(x)
502 # define WIFSIGNALED(x) (WTERMSIG (x) != 0 && WTERMSIG(x) != 0x7f)
505 # define WIFEXITED(x) (WTERMSIG (x) == 0)
508 # define WIFSTOPPED(x) (WTERMSIG (x) == 0x7f)
511 /* The termination signal. Only to be accessed if WIFSIGNALED(x) is true. */
513 # define WTERMSIG(x) ((x) & 0x7f)
516 /* The exit status. Only to be accessed if WIFEXITED(x) is true. */
518 # define WEXITSTATUS(x) (((x) >> 8) & 0xff)
521 /* The stopping signal. Only to be accessed if WIFSTOPPED(x) is true. */
523 # define WSTOPSIG(x) (((x) >> 8) & 0x7f)
526 /* True if the process dumped core. Not standardized by POSIX. */
528 # define WCOREDUMP(x) ((x) & 0x80)
532 /* Native Windows API. */
534 # include <signal.h> /* for SIGTERM */
536 /* The following macros apply to an argument x, that is a status of a process,
537 as returned by waitpid() or, equivalently, _cwait() or GetExitCodeProcess().
538 This value is simply an 'int', not composed of bit fields. */
540 /* When an unhandled fatal signal terminates a process, the exit code is 3. */
541 # define WIFSIGNALED(x) ((x) == 3)
542 # define WIFEXITED(x) ((x) != 3)
543 # define WIFSTOPPED(x) 0
545 /* The signal that terminated a process is not known posthum. */
546 # define WTERMSIG(x) SIGTERM
548 # define WEXITSTATUS(x) (x)
550 /* There are no stopping signals. */
551 # define WSTOPSIG(x) 0
553 /* There are no core dumps. */
554 # define WCOREDUMP(x) 0
559 /* Declarations of functions. */
562 # if defined _WIN32 && ! defined __CYGWIN__
563 _GL_FUNCDECL_SYS (waitpid
, pid_t
, (pid_t pid
, int *statusp
, int options
));
565 _GL_CXXALIAS_SYS (waitpid
, pid_t
, (pid_t pid
, int *statusp
, int options
));
566 _GL_CXXALIASWARN (waitpid
);
567 #elif defined GNULIB_POSIXCHECK
569 # if HAVE_RAW_DECL_WAITPID
570 _GL_WARN_ON_USE (waitpid
, "waitpid is unportable - "
571 "use gnulib module sys_wait for portability");
576 #endif /* _GL_SYS_WAIT_H */
577 #endif /* _GL_SYS_WAIT_H */