diff options
author | ache <ache@FreeBSD.org> | 2001-12-02 09:15:54 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2001-12-02 09:15:54 +0000 |
commit | 0d916b164851ca6a8393c4d1b379883bafaf854f (patch) | |
tree | 01d842dd70781a93a969d31415ffff3267002efa /lib/libc/stdlib/strtoul.c | |
parent | f2aa6ac13fd55dd1b12a2a9b7a7eb09856f0e5fd (diff) | |
download | FreeBSD-src-0d916b164851ca6a8393c4d1b379883bafaf854f.zip FreeBSD-src-0d916b164851ca6a8393c4d1b379883bafaf854f.tar.gz |
Make it works for non ASCII compatible encodings too.
The only assumption left is that 'A'..'Z' 'a'..'z' both are contiguous
Diffstat (limited to 'lib/libc/stdlib/strtoul.c')
-rw-r--r-- | lib/libc/stdlib/strtoul.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/libc/stdlib/strtoul.c b/lib/libc/stdlib/strtoul.c index e431dc8..1fd800a 100644 --- a/lib/libc/stdlib/strtoul.c +++ b/lib/libc/stdlib/strtoul.c @@ -58,7 +58,7 @@ strtoul(nptr, endptr, base) unsigned long acc; unsigned char c; unsigned long cutoff; - int neg, any, cutlim; + int neg, any, cutlim, n; /* * See strtol for comments as to the logic used. @@ -91,19 +91,19 @@ strtoul(nptr, endptr, base) cutlim = ULONG_MAX % base; for ( ; ; c = *s++) { if (isxdigit(c)) - c = digittoint(c); - else if (isascii(c) && isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; + n = digittoint(c); + else if (isalpha(c)) + n = (char)c - (isupper(c) ? 'A' - 10 : 'a' - 10); else break; - if (c >= base) + if (n < 0 || n >= base) break; - if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + if (any < 0 || acc > cutoff || (acc == cutoff && n > cutlim)) any = -1; else { any = 1; acc *= base; - acc += c; + acc += n; } } if (any < 0) { |