From 2c347aae8ab225cc873b7c36c8a1c73ca6ee4123 Mon Sep 17 00:00:00 2001 From: nic-gaffney Date: Tue, 27 Jun 2023 12:29:42 -0500 Subject: Fixed wait --- std/stdlib.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'std/stdlib.c') diff --git a/std/stdlib.c b/std/stdlib.c index b70f5b7..dcb7ec3 100644 --- a/std/stdlib.c +++ b/std/stdlib.c @@ -1,9 +1,26 @@ -#include +#include #include #include +#include -void wait(float x) { - sleep(x); +int wait(int msec) { + struct timespec ts; + int res; + + if (msec < 0) + { + errno = EINVAL; + return -1; + } + + ts.tv_sec = msec / 1000; + ts.tv_nsec = (msec % 1000) * 1000000; + + do { + res = nanosleep(&ts, &ts); + } while (res && errno == EINTR); + + return res; } int slen(char *str) { -- cgit v1.2.3