waitstatus.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* Definitions of status bits for `wait' et al.
  2. Copyright (C) 1992,1994,1996,1997,2000,2004 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 exit(N). */
  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. * Note that status 0x007f is "died from signal 127", not "stopped by signal 0".
  29. * This does happen on MIPS.
  30. * The comparison is "< 0xff", not "< 0x7f", because WCOREDUMP bit (0x80)
  31. * can be set too.
  32. */
  33. #define __WIFSIGNALED(status) (((unsigned)((status) & 0xffff) - 1U) < 0xffU)
  34. /* Nonzero if STATUS indicates the child is stopped. */
  35. #if !defined(__mips__)
  36. #define __WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
  37. #else
  38. #define __WIFSTOPPED(status) (((status) & 0xff) == 0x7f && ((status) & 0xff00))
  39. #endif
  40. /* Nonzero if STATUS indicates the child continued after a stop. We only
  41. define this if <bits/waitflags.h> provides the WCONTINUED flag bit. */
  42. #ifdef WCONTINUED
  43. # define __WIFCONTINUED(status) ((status) == __W_CONTINUED)
  44. #endif
  45. /* Nonzero if STATUS indicates the child dumped core. */
  46. #define __WCOREDUMP(status) ((status) & __WCOREFLAG)
  47. /* Macros for constructing status values. */
  48. #define __W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
  49. #define __W_STOPCODE(sig) ((sig) << 8 | 0x7f)
  50. #define __W_CONTINUED 0xffff
  51. #define __WCOREFLAG 0x80
  52. #ifdef __USE_BSD
  53. # include <endian.h>
  54. union wait
  55. {
  56. int w_status;
  57. struct
  58. {
  59. # if __BYTE_ORDER == __LITTLE_ENDIAN
  60. unsigned int __w_termsig:7; /* Terminating signal. */
  61. unsigned int __w_coredump:1; /* Set if dumped core. */
  62. unsigned int __w_retcode:8; /* Return code if exited normally. */
  63. unsigned int:16;
  64. # endif /* Little endian. */
  65. # if __BYTE_ORDER == __BIG_ENDIAN
  66. unsigned int:16;
  67. unsigned int __w_retcode:8;
  68. unsigned int __w_coredump:1;
  69. unsigned int __w_termsig:7;
  70. # endif /* Big endian. */
  71. } __wait_terminated;
  72. struct
  73. {
  74. # if __BYTE_ORDER == __LITTLE_ENDIAN
  75. unsigned int __w_stopval:8; /* W_STOPPED if stopped. */
  76. unsigned int __w_stopsig:8; /* Stopping signal. */
  77. unsigned int:16;
  78. # endif /* Little endian. */
  79. # if __BYTE_ORDER == __BIG_ENDIAN
  80. unsigned int:16;
  81. unsigned int __w_stopsig:8; /* Stopping signal. */
  82. unsigned int __w_stopval:8; /* W_STOPPED if stopped. */
  83. # endif /* Big endian. */
  84. } __wait_stopped;
  85. };
  86. # define w_termsig __wait_terminated.__w_termsig
  87. # define w_coredump __wait_terminated.__w_coredump
  88. # define w_retcode __wait_terminated.__w_retcode
  89. # define w_stopsig __wait_stopped.__w_stopsig
  90. # define w_stopval __wait_stopped.__w_stopval
  91. #endif /* Use BSD. */