diff options
Diffstat (limited to 'lib/libc/stdlib/strtoull.c')
-rw-r--r-- | lib/libc/stdlib/strtoull.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/libc/stdlib/strtoull.c b/lib/libc/stdlib/strtoull.c index d9e3e4f..09bd8b4 100644 --- a/lib/libc/stdlib/strtoull.c +++ b/lib/libc/stdlib/strtoull.c @@ -56,9 +56,9 @@ strtoull(nptr, endptr, base) { const char *s; unsigned long long acc; - unsigned char c; + char c; unsigned long long cutoff; - int neg, any, cutlim, n; + int neg, any, cutlim; /* * See strtoq for comments as to the logic used. @@ -66,7 +66,7 @@ strtoull(nptr, endptr, base) s = nptr; do { c = *s++; - } while (isspace(c)); + } while (isspace((unsigned char)c)); if (c == '-') { neg = 1; c = *s++; @@ -90,20 +90,22 @@ strtoull(nptr, endptr, base) cutoff = ULLONG_MAX / base; cutlim = ULLONG_MAX % base; for ( ; ; c = *s++) { - if (isxdigit(c)) - n = digittoint(c); - else if (isalpha(c)) - n = (char)c - (isupper(c) ? 'A' - 10 : 'a' - 10); + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; else break; - if (n < 0 || n >= base) + if (c >= base) break; - if (any < 0 || acc > cutoff || (acc == cutoff && n > cutlim)) + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) any = -1; else { any = 1; acc *= base; - acc += n; + acc += c; } } if (any < 0) { |