From 06a8d5d89d15050ed3c3586c0ea6c76c0a91a009 Mon Sep 17 00:00:00 2001
From: Jasen Borisov <jamadazi@protonmail.ch>
Date: Wed, 20 Jun 2018 19:36:36 +0100
Subject: [PATCH] sys_wait: implement C macros properly

Remove the broken Rust functions and instead provide C macros in a
`include/bits` header. The C macros were taken from musl.
---
 include/bits/sys/wait.h    | 13 ++++++++++++
 src/sys_wait/cbindgen.toml |  1 +
 src/sys_wait/src/lib.rs    | 41 --------------------------------------
 3 files changed, 14 insertions(+), 41 deletions(-)
 create mode 100644 include/bits/sys/wait.h

diff --git a/include/bits/sys/wait.h b/include/bits/sys/wait.h
new file mode 100644
index 000000000..94d5a2ba0
--- /dev/null
+++ b/include/bits/sys/wait.h
@@ -0,0 +1,13 @@
+#ifndef _BITS_SYS_WAIT_H
+#define _BITS_SYS_WAIT_H
+
+#define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
+#define WTERMSIG(s) ((s) & 0x7f)
+#define WSTOPSIG(s) WEXITSTATUS(s)
+#define WCOREDUMP(s) ((s) & 0x80)
+#define WIFEXITED(s) (!WTERMSIG(s))
+#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001)>>8) > 0x7f00)
+#define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu)
+#define WIFCONTINUED(s) ((s) == 0xffff)
+
+#endif /* _BITS_SYS_WAIT_H */
diff --git a/src/sys_wait/cbindgen.toml b/src/sys_wait/cbindgen.toml
index 528282cf3..7fd086007 100644
--- a/src/sys_wait/cbindgen.toml
+++ b/src/sys_wait/cbindgen.toml
@@ -1,6 +1,7 @@
 sys_includes = ["sys/types.h", "sys/resource.h"]
 include_guard = "_SYS_WAIT_H"
 style = "Tag"
+trailer = "#include <bits/sys/wait.h>"
 language = "C"
 
 [enum]
diff --git a/src/sys_wait/src/lib.rs b/src/sys_wait/src/lib.rs
index 9d5c3cc60..7496ed9ad 100644
--- a/src/sys_wait/src/lib.rs
+++ b/src/sys_wait/src/lib.rs
@@ -21,47 +21,6 @@ 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_int) < 0xff) as c_int
-}
-
-#[inline]
-pub fn WIFCONTINUED(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