+/*
+ * Macros to test the exit status returned by wait
+ * and extract the relevant values.
+ */
+#if defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE)
+#define _W_INT(i) (i)
+#else
+#define _W_INT(w) (*(int *)&(w)) /* convert union wait to int */
+#define WCOREFLAG 0200
+#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
+
+/* These macros are permited, as they are in the implementation namespace */
+#define _WSTATUS(x) (_W_INT(x) & 0177)
+#define _WSTOPPED 0177 /* _WSTATUS if process is stopped */
+
+/*
+ * [XSI] The <sys/wait.h> header shall define the following macros for
+ * analysis of process status values
+ */
+#if __DARWIN_UNIX03
+#define WEXITSTATUS(x) ((_W_INT(x) >> 8) & 0x000000ff)
+#else /* !__DARWIN_UNIX03 */
+#define WEXITSTATUS(x) (_W_INT(x) >> 8)
+#endif /* !__DARWIN_UNIX03 */
+/* 0x13 == SIGCONT */
+#define WSTOPSIG(x) (_W_INT(x) >> 8)
+#define WIFCONTINUED(x) (_WSTATUS(x) == _WSTOPPED && WSTOPSIG(x) == 0x13)
+#define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED && WSTOPSIG(x) != 0x13)
+#define WIFEXITED(x) (_WSTATUS(x) == 0)
+#define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0)
+#define WTERMSIG(x) (_WSTATUS(x))
+#if (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
+#define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG)
+
+#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
+#define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED)
+#endif /* (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) */
+
+/*
+ * [XSI] The following symbolic constants shall be defined as possible
+ * values for the fourth argument to waitid().
+ */
+/* WNOHANG already defined for wait4() */
+/* WUNTRACED defined for wait4() but not for waitid() */
+#define WEXITED 0x00000004 /* [XSI] Processes which have exitted */
+#if __DARWIN_UNIX03
+/* waitid() parameter */
+#define WSTOPPED 0x00000008 /* [XSI] Any child stopped by signal */
+#endif
+#define WCONTINUED 0x00000010 /* [XSI] Any child stopped then continued */
+#define WNOWAIT 0x00000020 /* [XSI] Leave process returned waitable */
+
+
+#if (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))