waitstatus.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Definitions of status bits for `wait' et al.
  2. Copyright (C) 1992-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #if !defined _SYS_WAIT_H && !defined _STDLIB_H
  16. # error "Never include <bits/waitstatus.h> directly; use <sys/wait.h> instead."
  17. #endif
  18. /* Everything extant so far uses these same bits. */
  19. /* If WIFEXITED(STATUS), the low-order 8 bits of the status. */
  20. #define __WEXITSTATUS(status) (((status) & 0xff00) >> 8)
  21. /* If WIFSIGNALED(STATUS), the terminating signal. */
  22. #define __WTERMSIG(status) ((status) & 0x7f)
  23. /* If WIFSTOPPED(STATUS), the signal that stopped the child. */
  24. #define __WSTOPSIG(status) __WEXITSTATUS(status)
  25. /* Nonzero if STATUS indicates normal termination. */
  26. #define __WIFEXITED(status) (__WTERMSIG(status) == 0)
  27. /* Nonzero if STATUS indicates termination by a signal. */
  28. #define __WIFSIGNALED(status) \
  29. (((signed char) (((status) & 0x7f) + 1) >> 1) > 0)
  30. /* Nonzero if STATUS indicates the child is stopped. */
  31. #define __WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
  32. /* Nonzero if STATUS indicates the child continued after a stop. We only
  33. define this if <bits/waitflags.h> provides the WCONTINUED flag bit. */
  34. #ifdef WCONTINUED
  35. # define __WIFCONTINUED(status) ((status) == __W_CONTINUED)
  36. #endif
  37. /* Nonzero if STATUS indicates the child dumped core. */
  38. #define __WCOREDUMP(status) ((status) & __WCOREFLAG)
  39. /* Macros for constructing status values. */
  40. #define __W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
  41. #define __W_STOPCODE(sig) ((sig) << 8 | 0x7f)
  42. #define __W_CONTINUED 0xffff
  43. #define __WCOREFLAG 0x80