diff options
author | dzwdz | 2023-06-02 15:25:11 +0200 |
---|---|---|
committer | dzwdz | 2023-06-02 15:25:11 +0200 |
commit | 8fd4943b2721696f86783d22dd2e8d593a22a766 (patch) | |
tree | 2e2e664605571a07688021339a6be0f395bc62c2 /src/user/lib/string/string.c | |
parent | 51c39c73692e755596eafb0d6f732581fee3ba98 (diff) |
libc: stub out sltar's requirements
Diffstat (limited to 'src/user/lib/string/string.c')
-rw-r--r-- | src/user/lib/string/string.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/user/lib/string/string.c b/src/user/lib/string/string.c index 8fdc7c7..7058573 100644 --- a/src/user/lib/string/string.c +++ b/src/user/lib/string/string.c @@ -3,17 +3,19 @@ #include <string.h> #include <strings.h> -long strtol(const char *restrict s, char **restrict end, int base) { +static unsigned long long +strton(const char *restrict s, char **restrict end, int base, int *sign) +{ long res = 0; - int sign = 1; while (isspace(*s)) s++; + if (sign) *sign = 1; if (*s == '+') { s++; } else if (*s == '-') { s++; - sign = -1; + if (sign) *sign = -1; } if (base == 0) { @@ -45,7 +47,21 @@ long strtol(const char *restrict s, char **restrict end, int base) { s++; } if (end) *end = (void*)s; - return res * sign; + return res; +} + +long strtol(const char *restrict s, char **restrict end, int base) { + int sign; + long n = strton(s, end, base, &sign); + return n * sign; +} + +unsigned long strtoul(const char *restrict s, char **restrict end, int base) { + return strton(s, end, base, NULL); +} + +unsigned long long strtoull(const char *restrict s, char **restrict end, int base) { + return strton(s, end, base, NULL); } #include <bits/panic.h> |