diff options
| author | Cody <cody@codyq.dev> | 2023-06-28 14:28:54 -0500 |
|---|---|---|
| committer | Cody <cody@codyq.dev> | 2023-06-28 14:28:54 -0500 |
| commit | 9c915d3bf79078a2afd9c70ed8bbf606c3250f84 (patch) | |
| tree | a7702cfa7b35e270b8be44b3566bcbf7a24d3cc2 /std/stdlib.c | |
| parent | da89b3f6cdf17dbaeba9aa25e22f1b8313f97536 (diff) | |
| parent | 42b509365ce43e2f83475cbbc0f01bcd7b34fcd3 (diff) | |
| download | sloth-9c915d3bf79078a2afd9c70ed8bbf606c3250f84.tar.gz | |
Merge branch 'master' of github.com:slothlang/slothlang
Diffstat (limited to 'std/stdlib.c')
| -rw-r--r-- | std/stdlib.c | 23 |
1 files changed, 20 insertions, 3 deletions
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 <unistd.h> +#include <errno.h> #include <stdlib.h> #include <string.h> +#include <time.h> -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) { |
