ksh_wait.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Wrapper around the ugly sys/wait includes/ifdefs */
  2. /* $Id$ */
  3. #ifdef HAVE_SYS_WAIT_H
  4. # include <sys/wait.h>
  5. #endif
  6. #ifndef POSIX_SYS_WAIT
  7. /* Get rid of system macros (which probably use union wait) */
  8. # undef WIFCORED
  9. # undef WIFEXITED
  10. # undef WEXITSTATUS
  11. # undef WIFSIGNALED
  12. # undef WTERMSIG
  13. # undef WIFSTOPPED
  14. # undef WSTOPSIG
  15. #endif /* POSIX_SYS_WAIT */
  16. typedef int WAIT_T;
  17. #ifndef WIFCORED
  18. # define WIFCORED(s) ((s) & 0x80)
  19. #endif
  20. #define WSTATUS(s) (s)
  21. #ifndef WIFEXITED
  22. # define WIFEXITED(s) (((s) & 0xff) == 0)
  23. #endif
  24. #ifndef WEXITSTATUS
  25. # define WEXITSTATUS(s) (((s) >> 8) & 0xff)
  26. #endif
  27. #ifndef WIFSIGNALED
  28. # define WIFSIGNALED(s) (((s) & 0xff) != 0 && ((s) & 0xff) != 0x7f)
  29. #endif
  30. #ifndef WTERMSIG
  31. # define WTERMSIG(s) ((s) & 0x7f)
  32. #endif
  33. #ifndef WIFSTOPPED
  34. # define WIFSTOPPED(s) (((s) & 0xff) == 0x7f)
  35. #endif
  36. #ifndef WSTOPSIG
  37. # define WSTOPSIG(s) (((s) >> 8) & 0xff)
  38. #endif
  39. #if !defined(HAVE_WAITPID) && defined(HAVE_WAIT3)
  40. /* always used with p == -1 */
  41. # define ksh_waitpid(p, s, o) wait3((s), (o), (struct rusage *) 0)
  42. #else /* !HAVE_WAITPID && HAVE_WAIT3 */
  43. # define ksh_waitpid(p, s, o) waitpid((p), (s), (o))
  44. #endif /* !HAVE_WAITPID && HAVE_WAIT3 */