From 8fd4943b2721696f86783d22dd2e8d593a22a766 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Fri, 2 Jun 2023 15:25:11 +0200 Subject: libc: stub out sltar's requirements --- src/user/lib/string/string.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/user/lib/string/string.c') 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 #include -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 -- cgit v1.2.3