diff options
author | Jakob Kaivo <jkk@ung.org> | 2020-08-12 15:14:06 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2020-08-12 15:14:06 -0400 |
commit | fe9e78411f270c8c86d75620bbaa53147b9c7daa (patch) | |
tree | 115d4e56a19875a21feaadd60ac860ad071c3023 | |
parent | 3230ceb35964a48db08d404c9b954fa29edde166 (diff) |
implement in terms of nanosleep()
-rw-r--r-- | src/unistd/sleep.c | 21 |
1 files 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 <unistd.h> -#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) |