From 3fa220237d1fd94c712a4c6a29319a3a01bb910a Mon Sep 17 00:00:00 2001
From: stratact <stratact1@gmail.com>
Date: Thu, 24 May 2018 20:55:42 -0700
Subject: [PATCH] Add `sys_wait` functions (Fixes #81)

---
 src/sys_wait/src/lib.rs | 53 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/src/sys_wait/src/lib.rs b/src/sys_wait/src/lib.rs
index 8881fb12..30c470b3 100644
--- a/src/sys_wait/src/lib.rs
+++ b/src/sys_wait/src/lib.rs
@@ -9,6 +9,59 @@ extern crate sys_resource;
 use platform::types::*;
 use sys_resource::rusage;
 
+pub const WNOHANG: c_int = 1;
+pub const WUNTRACED: c_int = 2;
+
+pub const WSTOPPED: c_int = 2;
+pub const WEXITED: c_int = 4
+pub const WCONTINUED: c_int = 8
+pub const WNOWAIT: c_int = 0x1000000
+
+pub const __WNOTHREAD: c_int = 0x20000000
+pub const __WALL: c_int = 0x40000000
+pub const __WCLONE: c_int = 0x80000000
+
+#[inline]
+pub fn WEXITSTATUS(status: c_int) -> c_int {
+    (status & 0xff00) >> 8
+}
+
+#[inline]
+pub fn WTERMSIG(status: c_int) -> c_int {
+    status & 0x7f
+}
+
+#[inline]
+pub fn WSTOPSIG(status: c_int) -> c_int {
+    WEXITSTATUS(status)
+}
+
+#[inline]
+pub fn WCOREDUMP(status: c_int) -> c_int {
+    status & 0x80
+}
+
+#[inline]
+pub fn WIFEXITED(status: c_int) -> c_int {
+    // This is simulate the Not operator when used for regular integers in C
+    (WTERMSIG(status) == 0) as c_int
+}
+
+#[inline]
+pub fn WIFSTOPPED(status: c_int) -> c_int {
+    (((((status & 0xffff) * 0x10001) >> 8) as c_short) > 0x7f00) as c_int
+}
+
+#[inline]
+pub fn WIFSIGNALED(status: c_int) -> c_int {
+    ((status & 0xffff) - (1 as c_uint) < 0xffu) as c_int
+}
+
+#[inline]
+pub fn WIFSIGNALED(status: c_int) -> c_int {
+    (status == 0xffff) as c_int
+}
+
 #[no_mangle]
 pub unsafe extern "C" fn wait(stat_loc: *mut c_int) -> pid_t {
     waitpid(!0, stat_loc, 0)
-- 
GitLab