aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authornic-gaffney <gaffney_nic@protonmail.com>2023-06-27 12:29:42 -0500
committernic-gaffney <gaffney_nic@protonmail.com>2023-06-27 12:29:42 -0500
commit2c347aae8ab225cc873b7c36c8a1c73ca6ee4123 (patch)
tree7d5c0fd3ad3646d9bbf70ba0012798bf8af199f9 /std
parent2cf498f7bf1311ebca156315a0c9ac25b0addef5 (diff)
downloadsloth-2c347aae8ab225cc873b7c36c8a1c73ca6ee4123.tar.gz
Fixed wait
Diffstat (limited to 'std')
-rw-r--r--std/stdlib.c23
-rw-r--r--std/stdlib.sloth2
2 files changed, 21 insertions, 4 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) {
diff --git a/std/stdlib.sloth b/std/stdlib.sloth
index eb6000d..ea57e45 100644
--- a/std/stdlib.sloth
+++ b/std/stdlib.sloth
@@ -1,4 +1,4 @@
-foreign fn wait(x: Float) Void;
+foreign fn wait(x: Int) Int;
foreign fn print(str: String) Void;
foreign fn slen(str: String) Int;
# foreign fn charAt(str: String) Char;