-#define WEXITSTATUS(x) (_W_INT(x) >> 8)
-#define WIFCONTINUED(x) (x == 0x13) /* 0x13 == SIGCONT */
-#define WIFEXITED(x) (_WSTATUS(x) == 0)
-#define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0)
-#define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED)
-#define WSTOPSIG(x) (_W_INT(x) >> 8)
-#define WTERMSIG(x) (_WSTATUS(x))
-#if !defined(_POSIX_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) */
+#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)) */