From 4d4ab1a75f06768d1112c7e2ec9eac2b21d07960 Mon Sep 17 00:00:00 2001
From: Paul Sajna <paulsajna@gmail.com>
Date: Fri, 9 Mar 2018 05:18:21 -0800
Subject: [PATCH] fix and test

---
 include/bits/timespec.h |  4 ++++
 include/sys/types.h     |  8 ++++++++
 src/time/cbindgen.toml  |  2 +-
 tests/.gitignore        |  3 +++
 tests/Makefile          |  3 ++-
 tests/sleep.c           | 13 +++++++++++++
 6 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 include/bits/timespec.h
 create mode 100644 tests/sleep.c

diff --git a/include/bits/timespec.h b/include/bits/timespec.h
new file mode 100644
index 00000000..52d696fc
--- /dev/null
+++ b/include/bits/timespec.h
@@ -0,0 +1,4 @@
+typedef struct {
+    time_t tv_sec;
+    long tv_nsec;
+} timespec;
diff --git a/include/sys/types.h b/include/sys/types.h
index 0813cddf..7312acfd 100644
--- a/include/sys/types.h
+++ b/include/sys/types.h
@@ -24,4 +24,12 @@ typedef long time_t;
 
 typedef int useconds_t;
 
+typedef long suseconds_t;
+
+typedef long clock_t;
+
+typedef int clockid_t;
+
+typedef void* timer_t;
+
 #endif /* _SYS_TYPES_H */
diff --git a/src/time/cbindgen.toml b/src/time/cbindgen.toml
index afc1ec21..ef3a5240 100644
--- a/src/time/cbindgen.toml
+++ b/src/time/cbindgen.toml
@@ -1,4 +1,4 @@
-sys_includes = ["sys/types.h"]
+sys_includes = ["sys/types.h", "bits/timespec.h", "stdint.h"]
 include_guard = "_TIME_H"
 language = "C"
 
diff --git a/tests/.gitignore b/tests/.gitignore
index 7b70bccf..98ef3557 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -20,7 +20,10 @@
 /link
 /link.out
 /math
+/setid
+/sleep
 /pipe
 /printf
 /rmdir
+/unlink
 /write
diff --git a/tests/Makefile b/tests/Makefile
index 6c2a838d..c60411f6 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -19,6 +19,7 @@ BINS=\
 	rmdir \
 	pipe \
 	printf \
+	sleep \
 	write
 
 all: $(BINS)
@@ -28,7 +29,7 @@ clean:
 
 run: $(BINS)
 	for bin in $(BINS); \
-	do
+	do \
 		echo "# $${bin} #"; \
 		"./$${bin}" test args; \
 	done
diff --git a/tests/sleep.c b/tests/sleep.c
new file mode 100644
index 00000000..ab66a4e7
--- /dev/null
+++ b/tests/sleep.c
@@ -0,0 +1,13 @@
+#include <time.h>
+#include <unistd.h>
+#include <stdio.h>
+
+int main(int argc, char** argv) {
+    sleep(2);
+    perror("sleep");
+    usleep(1000);
+    perror("usleep");
+    timespec tm = {0, 10000};
+    nanosleep(&tm, NULL);
+    perror("nanosleep");
+}
-- 
GitLab