waitstatus.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Definitions of status bits for `wait' et al.
  2. Copyright (C) 1992, 1994, 1996, 1997 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 Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. 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. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with the GNU C Library; see the file COPYING.LIB. If not,
  14. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA. */
  16. #ifndef _SYS_WAIT_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. #ifdef __GNUC__
  30. # define __WIFSIGNALED(status) \
  31. (__extension__ ({ int __status = (status); \
  32. !__WIFSTOPPED(__status) && !__WIFEXITED(__status); }))
  33. #else /* Not GCC. */
  34. # define __WIFSIGNALED(status) (!__WIFSTOPPED(status) && !__WIFEXITED(status))
  35. #endif /* GCC. */
  36. /* Nonzero if STATUS indicates the child is stopped. */
  37. #define __WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
  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 __WCOREFLAG 0x80
  44. #ifdef __USE_BSD
  45. # include <endian.h>
  46. union wait
  47. {
  48. int w_status;
  49. struct
  50. {
  51. # if __BYTE_ORDER == __LITTLE_ENDIAN
  52. unsigned int __w_termsig:7; /* Terminating signal. */
  53. unsigned int __w_coredump:1; /* Set if dumped core. */
  54. unsigned int __w_retcode:8; /* Return code if exited normally. */
  55. unsigned int:16;
  56. # endif /* Little endian. */
  57. # if __BYTE_ORDER == __BIG_ENDIAN
  58. unsigned int:16;
  59. unsigned int __w_retcode:8;
  60. unsigned int __w_coredump:1;
  61. unsigned int __w_termsig:7;
  62. # endif /* Big endian. */
  63. } __wait_terminated;
  64. struct
  65. {
  66. # if __BYTE_ORDER == __LITTLE_ENDIAN
  67. unsigned int __w_stopval:8; /* W_STOPPED if stopped. */
  68. unsigned int __w_stopsig:8; /* Stopping signal. */
  69. unsigned int:16;
  70. # endif /* Little endian. */
  71. # if __BYTE_ORDER == __BIG_ENDIAN
  72. unsigned int:16;
  73. unsigned int __w_stopsig:8; /* Stopping signal. */
  74. unsigned int __w_stopval:8; /* W_STOPPED if stopped. */
  75. # endif /* Big endian. */
  76. } __wait_stopped;
  77. };
  78. # define w_termsig __wait_terminated.__w_termsig
  79. # define w_coredump __wait_terminated.__w_coredump
  80. # define w_retcode __wait_terminated.__w_retcode
  81. # define w_stopsig __wait_stopped.__w_stopsig
  82. # define w_stopval __wait_stopped.__w_stopval
  83. #endif /* Use BSD. */