From fe9e78411f270c8c86d75620bbaa53147b9c7daa Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Wed, 12 Aug 2020 15:14:06 -0400 Subject: implement in terms of nanosleep() --- src/unistd/sleep.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/unistd/sleep.c b/src/unistd/sleep.c index 29ffee7b..9af72481 100644 --- a/src/unistd/sleep.c +++ b/src/unistd/sleep.c @@ -1,15 +1,24 @@ #include "stddef.h" #include "sys/types.h" #include -#include "../_syscall.h" +#include "time.h" + +#if _POSIX_C_SOURCE < 199309 +#define nanosleep __nanosleep +#include "../time/struct_timespec.c" +#include "../time/nanosleep.c" +#endif unsigned sleep(unsigned seconds) { - #if 0 - SC(unsigned, seconds); - #else - return seconds; - #endif + struct timespec tosleep = { seconds, 0 }; + struct timespec remaining = { 0 , 0 }; + + if (nanosleep(&tosleep, &remaining) == -1) { + return seconds; + } + + return remaining.tv_sec; } /* POSIX(1) -- cgit v1.2.1