summaryrefslogtreecommitdiffstats
path: root/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c')
-rw-r--r--libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c b/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c
new file mode 100644
index 0000000..8005f17
--- /dev/null
+++ b/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c
@@ -0,0 +1,18 @@
+// Copyright (c) 2016 Nuxi, https://nuxi.nl/
+//
+// SPDX-License-Identifier: BSD-2-Clause
+
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+int usleep(useconds_t useconds) {
+ struct timespec ts = {.tv_sec = useconds / 1000000,
+ .tv_nsec = useconds % 1000000 * 1000};
+ int error = clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL);
+ if (error != 0) {
+ errno = error;
+ return -1;
+ }
+ return 0;
+}