waitstatus.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #if !defined _SYS_WAIT_H && !defined _STDLIB_H
  17. # error "Never include <bits/waitstatus.h> directly; use <sys/wait.h> instead."
  18. #endif
  19. /* Everything extant so far uses these same bits. */
  20. /* If WIFEXITED(STATUS), the low-order 8 bits of the status. */
  21. #define __WEXITSTATUS(status) (((status) & 0xff00) >> 8)
  22. /* If WIFSIGNALED(STATUS), the terminating signal. */
  23. #define __WTERMSIG(status) ((status) & 0x7f)
  24. /* If WIFSTOPPED(STATUS), the signal that stopped the child. */
  25. #define __WSTOPSIG(status) __WEXITSTATUS(status)
  26. /* Nonzero if STATUS indicates normal termination. */
  27. #define __WIFEXITED(status) (__WTERMSIG(status) == 0)
  28. /* Nonzero if STATUS indicates termination by a signal. */
  29. #define __WIFSIGNALED(status) \
  30. (((signed char) (((status) & 0x7f) + 1) >> 1) > 0)
  31. /* Nonzero if STATUS indicates the child is stopped. */
  32. #define __WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
  33. /* Nonzero if STATUS indicates the child continued after a stop. We only
  34. define this if <bits/waitflags.h> provides the WCONTINUED flag bit. */
  35. #ifdef WCONTINUED
  36. # define __WIFCONTINUED(status) ((status) == __W_CONTINUED)
  37. #endif
  38. /* Nonzero if STATUS indicates the child dumped core. */
  39. #define __WCOREDUMP(status) ((status) & __WCOREFLAG)
  40. /* Macros for constructing status values. */
  41. #define __W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
  42. #define __W_STOPCODE(sig) ((sig) << 8 | 0x7f)
  43. #define __W_CONTINUED 0xffff
  44. #define __WCOREFLAG 0x80
  45. #ifdef __USE_BSD
  46. # include <endian.h>
  47. union wait
  48. {
  49. int w_status;
  50. struct
  51. {
  52. # if __BYTE_ORDER == __LITTLE_ENDIAN
  53. unsigned int __w_termsig:7; /* Terminating signal. */
  54. unsigned int __w_coredump:1; /* Set if dumped core. */
  55. unsigned int __w_retcode:8; /* Return code if exited normally. */
  56. unsigned int:16;
  57. # endif /* Little endian. */
  58. # if __BYTE_ORDER == __BIG_ENDIAN
  59. unsigned int:16;
  60. unsigned int __w_retcode:8;
  61. unsigned int __w_coredump:1;
  62. unsigned int __w_termsig:7;
  63. # endif /* Big endian. */
  64. } __wait_terminated;
  65. struct
  66. {
  67. # if __BYTE_ORDER == __LITTLE_ENDIAN
  68. unsigned int __w_stopval:8; /* W_STOPPED if stopped. */
  69. unsigned int __w_stopsig:8; /* Stopping signal. */
  70. unsigned int:16;
  71. # endif /* Little endian. */
  72. # if __BYTE_ORDER == __BIG_ENDIAN
  73. unsigned int:16;
  74. unsigned int __w_stopsig:8; /* Stopping signal. */
  75. unsigned int __w_stopval:8; /* W_STOPPED if stopped. */
  76. # endif /* Big endian. */
  77. } __wait_stopped;
  78. };
  79. # define w_termsig __wait_terminated.__w_termsig
  80. # define w_coredump __wait_terminated.__w_coredump
  81. # define w_retcode __wait_terminated.__w_retcode
  82. # define w_stopsig __wait_stopped.__w_stopsig
  83. # define w_stopval __wait_stopped.__w_stopval
  84. #endif /* Use BSD. */