diff options
| author | nic-gaffney <gaffney_nic@protonmail.com> | 2023-06-25 23:21:02 -0500 |
|---|---|---|
| committer | nic-gaffney <gaffney_nic@protonmail.com> | 2023-06-25 23:21:02 -0500 |
| commit | c3bb1751d7f62a13a46f28c1eb67d9e20d8d6f7f (patch) | |
| tree | 7208642d10240c539405b4e1759576d3da5f468a | |
| parent | 578229132e35075ef191ee960460d237c3ace3b8 (diff) | |
| download | sloth-c3bb1751d7f62a13a46f28c1eb67d9e20d8d6f7f.tar.gz | |
Fixed standard library
| -rw-r--r-- | std/stdio.c | 2 | ||||
| -rw-r--r-- | std/stdlib.c | 14 | ||||
| -rw-r--r-- | std/stdlib.sloth | 1 | ||||
| -rw-r--r-- | std/stdmath.c | 10 |
4 files changed, 16 insertions, 11 deletions
diff --git a/std/stdio.c b/std/stdio.c index d1bc69a..1a4d98c 100644 --- a/std/stdio.c +++ b/std/stdio.c @@ -8,5 +8,5 @@ char* readln() { } void print(char *str) { - puts(str); + fputs(str, stdout); } diff --git a/std/stdlib.c b/std/stdlib.c index d27b36f..7e77385 100644 --- a/std/stdlib.c +++ b/std/stdlib.c @@ -1,13 +1,19 @@ #include <unistd.h> +#include <stdlib.h> +#include <string.h> void wait(long long x) { sleep(x); } -int slen(char *str) { - return strlen(str); +long long slen(char *str) { + return (long long) strlen(str); } -char charAt(char *str, int) { - return str[int]; +char charAt(char *str, long long x) { + return str[x]; +} + +long long parse_int(char *str) { + return (long long) atoi(str); } diff --git a/std/stdlib.sloth b/std/stdlib.sloth index b1849e3..d7ddeff 100644 --- a/std/stdlib.sloth +++ b/std/stdlib.sloth @@ -2,6 +2,7 @@ foreign fn wait(x: Int) Void; foreign fn print(str: String) Void; foreign fn slen(str: String) Int; foreign fn charAt(str: String) Char; +foreign fn parse_int(str: String) Int; fn termpos(x: int, y: int) Void { print("\x1b["); diff --git a/std/stdmath.c b/std/stdmath.c index c9a91c3..dad292f 100644 --- a/std/stdmath.c +++ b/std/stdmath.c @@ -2,10 +2,8 @@ #include <stdlib.h> #include <time.h> -int randGen(int min, int max) { - time_t t; - - srand((unsigned) time(&t)); - - return rand() % (max - min + 1) + min; + +long long randGen(long long min, long long max) { + srandom((unsigned) time(NULL)); + return random() % (max - min + 1) + min; } |
