From d64dba1c1eccaba6b4f4d761e8841124640a9886 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Sat, 3 Mar 2018 13:05:43 -0700
Subject: [PATCH] Use patched cbindgen, implement stdbool and stdint

---
 .gitmodules       |  3 +++
 Cargo.toml        |  4 ----
 cbindgen          |  1 +
 fcntl/Cargo.toml  |  2 +-
 include/stdbool.h |  9 +++++++++
 include/stdint.h  | 49 +++++++++++++++++++++++++++++++++++++++++++++--
 include/stdlib.h  |  6 ------
 unistd/Cargo.toml |  2 +-
 8 files changed, 62 insertions(+), 14 deletions(-)
 create mode 160000 cbindgen
 delete mode 100644 include/stdlib.h

diff --git a/.gitmodules b/.gitmodules
index ba57c697c..271673cd4 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,6 @@
 [submodule "openlibm"]
 	path = openlibm
 	url = https://github.com/redox-os/openlibm.git
+[submodule "cbindgen"]
+	path = cbindgen
+	url = https://github.com/redox-os/cbindgen.git
diff --git a/Cargo.toml b/Cargo.toml
index 2cb2133a1..7c83df5ab 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,10 +8,6 @@ name = "c"
 crate-type = ["staticlib"]
 
 [workspace]
-members = [
-    "fcntl",
-    "unistd"
-]
 
 [dependencies]
 fcntl = { path = "fcntl" }
diff --git a/cbindgen b/cbindgen
new file mode 160000
index 000000000..97ceb5862
--- /dev/null
+++ b/cbindgen
@@ -0,0 +1 @@
+Subproject commit 97ceb5862f397b14c5b63cd60af7f5f345ad065c
diff --git a/fcntl/Cargo.toml b/fcntl/Cargo.toml
index ca316750d..3527c6e77 100644
--- a/fcntl/Cargo.toml
+++ b/fcntl/Cargo.toml
@@ -5,7 +5,7 @@ authors = ["Jeremy Soller <jackpot51@gmail.com>"]
 build = "build.rs"
 
 [build-dependencies]
-cbindgen = "0.5"
+cbindgen = { path = "../cbindgen" }
 
 [dependencies]
 common = { path = "../common" }
diff --git a/include/stdbool.h b/include/stdbool.h
index e69de29bb..1a9f870bb 100644
--- a/include/stdbool.h
+++ b/include/stdbool.h
@@ -0,0 +1,9 @@
+#ifndef _STDBOOL_H
+#define _STDBOOL_H
+
+typedef _Bool bool;
+#define true 1
+#define false 0
+#define __bool_true_false_are_defined 1
+
+#endif /* _STDBOOL_H */
diff --git a/include/stdint.h b/include/stdint.h
index d7fa66c94..ade0ab4fe 100644
--- a/include/stdint.h
+++ b/include/stdint.h
@@ -1,7 +1,52 @@
 #ifndef _STDINT_H
 #define _STDINT_H
 
-typedef int int32_t;
-typedef int intptr_t;
+#define INT8_MIN -0x80
+#define INT8_MAX 0x7F
+typedef signed char int8_t;
+
+#define UINT8_MIN 0x00
+#define UINT8_MAX 0xFF
+typedef unsigned char uint8_t;
+
+#define INT16_MIN -0x8000
+#define INT16_MAX 0x7FFF
+typedef signed short int16_t;
+
+#define UINT16_MIN 0x0000
+#define UINT16_MAX 0xFFFF
+typedef unsigned short uint16_t;
+
+#define INT32_MIN -0x80000000
+#define INT32_MAX 0x7FFFFFFF
+typedef signed long int32_t;
+
+#define UINT32_MIN 0x00000000
+#define UINT32_MAX 0xFFFFFFFF
+typedef unsigned long uint32_t;
+
+#define INT64_MIN -0x8000000000000000
+#define INT64_MAX 0x7FFFFFFFFFFFFFFF
+typedef signed long long int64_t;
+
+#define UINT64_MIN 0x0000000000000000
+#define UINT64_MAX 0xFFFFFFFFFFFFFFFF
+typedef unsigned long long uint64_t;
+
+#define INTPTR_MIN INT64_MIN
+#define INTPTR_MAX INT64_MAX
+typedef int64_t intptr_t;
+
+#define UINTPTR_MIN UINT64_MIN
+#define UINTPTR_MAX UINT64_MAX
+typedef uint64_t uintptr_t;
+
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+typedef int64_t intmax_t;
+
+#define UINTMAX_MIN UINT64_MIN
+#define UINTMAX_MAX UINT64_MAX
+typedef uint64_t uintmax_t;
 
 #endif /* _STDINT_H */
diff --git a/include/stdlib.h b/include/stdlib.h
deleted file mode 100644
index d5f3b03cb..000000000
--- a/include/stdlib.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _STDLIB_H
-#define _STDLIB_H
-
-#include <sys/types.h>
-
-#endif /* _STDLIB_H */
diff --git a/unistd/Cargo.toml b/unistd/Cargo.toml
index 9e2a47095..0a7878fe7 100644
--- a/unistd/Cargo.toml
+++ b/unistd/Cargo.toml
@@ -5,7 +5,7 @@ authors = ["Jeremy Soller <jackpot51@gmail.com>"]
 build = "build.rs"
 
 [build-dependencies]
-cbindgen = "0.5"
+cbindgen = { path = "../cbindgen" }
 
 [dependencies]
 common = { path = "../common" }
-- 
GitLab