summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>2001-11-28 00:48:11 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>2001-11-28 00:48:11 +0000
commit7e302fc7a2591a1f26d7f94ef7d4292930773148 (patch)
tree39609fa880161cf047c27ac96bdf1f70f43a0e14 /lib/libc/stdlib
parentd262b81bdb16514d281404c8eac9a9c9165554cf (diff)
Notes
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/strtol.c24
-rw-r--r--lib/libc/stdlib/strtoll.c24
-rw-r--r--lib/libc/stdlib/strtoq.c3
-rw-r--r--lib/libc/stdlib/strtoul.c22
-rw-r--r--lib/libc/stdlib/strtoull.c22
-rw-r--r--lib/libc/stdlib/strtouq.c3
6 files changed, 42 insertions, 56 deletions
diff --git a/lib/libc/stdlib/strtol.c b/lib/libc/stdlib/strtol.c
index 3bb13e1c94e3..10d7425c0f89 100644
--- a/lib/libc/stdlib/strtol.c
+++ b/lib/libc/stdlib/strtol.c
@@ -53,13 +53,13 @@ long
strtol(nptr, endptr, base)
const char *nptr;
char **endptr;
- register int base;
+ int base;
{
- register const char *s;
- register unsigned long acc;
- register unsigned char c;
- register unsigned long cutoff;
- register int neg, any, cutlim;
+ const char *s;
+ unsigned long acc;
+ unsigned char c;
+ unsigned long cutoff;
+ int neg, any, cutlim;
/*
* Skip white space and pick up leading +/- sign if any.
@@ -87,7 +87,7 @@ strtol(nptr, endptr, base)
if (base == 0)
base = c == '0' ? 8 : 10;
acc = any = 0;
- if (base < 2 || base > 36)
+ if (base < 2)
goto noconv;
/*
@@ -107,16 +107,14 @@ strtol(nptr, endptr, base)
* Set 'any' if any `digits' consumed; make it negative to indicate
* overflow.
*/
- cutoff = neg ? -(LONG_MIN + LONG_MAX) + (unsigned long)LONG_MAX
+ cutoff = neg ? (unsigned long)-(LONG_MIN + LONG_MAX) + LONG_MAX
: LONG_MAX;
cutlim = cutoff % base;
cutoff /= base;
for ( ; ; c = *s++) {
- if (!isascii(c))
- break;
- if (isdigit(c))
- c -= '0';
- else if (isalpha(c))
+ if (isxdigit(c))
+ c = digittoint(c);
+ else if (isascii(c) && isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
diff --git a/lib/libc/stdlib/strtoll.c b/lib/libc/stdlib/strtoll.c
index 0ce39094e306..5d656c1bee3c 100644
--- a/lib/libc/stdlib/strtoll.c
+++ b/lib/libc/stdlib/strtoll.c
@@ -52,13 +52,13 @@ long long
strtoll(nptr, endptr, base)
const char *nptr;
char **endptr;
- register int base;
+ int base;
{
- register const char *s;
- register unsigned long long acc;
- register unsigned char c;
- register unsigned long long cutoff;
- register int neg, any, cutlim;
+ const char *s;
+ unsigned long long acc;
+ unsigned char c;
+ unsigned long long cutoff;
+ int neg, any, cutlim;
/*
* Skip white space and pick up leading +/- sign if any.
@@ -86,7 +86,7 @@ strtoll(nptr, endptr, base)
if (base == 0)
base = c == '0' ? 8 : 10;
acc = any = 0;
- if (base < 2 || base > 36)
+ if (base < 2)
goto noconv;
/*
@@ -107,16 +107,14 @@ strtoll(nptr, endptr, base)
* Set 'any' if any `digits' consumed; make it negative to indicate
* overflow.
*/
- cutoff = neg ? -(LLONG_MIN + LLONG_MAX) + (unsigned long long)LLONG_MAX
+ cutoff = neg ? (unsigned long long)-(LLONG_MIN + LLONG_MAX) + LLONG_MAX
: LLONG_MAX;
cutlim = cutoff % base;
cutoff /= base;
for ( ; ; c = *s++) {
- if (!isascii(c))
- break;
- if (isdigit(c))
- c -= '0';
- else if (isalpha(c))
+ if (isxdigit(c))
+ c = digittoint(c);
+ else if (isascii(c) && isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
diff --git a/lib/libc/stdlib/strtoq.c b/lib/libc/stdlib/strtoq.c
index 853ef434d68d..10b674ba9ce4 100644
--- a/lib/libc/stdlib/strtoq.c
+++ b/lib/libc/stdlib/strtoq.c
@@ -43,9 +43,6 @@ static char sccsid[] = "@(#)strtoq.c 8.1 (Berkeley) 6/4/93";
/*
* Convert a string to a quad integer.
- *
- * Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
*/
quad_t
strtoq(nptr, endptr, base)
diff --git a/lib/libc/stdlib/strtoul.c b/lib/libc/stdlib/strtoul.c
index 1f23368f5cbd..e952663c533e 100644
--- a/lib/libc/stdlib/strtoul.c
+++ b/lib/libc/stdlib/strtoul.c
@@ -52,13 +52,13 @@ unsigned long
strtoul(nptr, endptr, base)
const char *nptr;
char **endptr;
- register int base;
+ int base;
{
- register const char *s;
- register unsigned long acc;
- register unsigned char c;
- register unsigned long cutoff;
- register int neg, any, cutlim;
+ const char *s;
+ unsigned long acc;
+ unsigned char c;
+ unsigned long cutoff;
+ int neg, any, cutlim;
/*
* See strtol for comments as to the logic used.
@@ -84,17 +84,15 @@ strtoul(nptr, endptr, base)
if (base == 0)
base = c == '0' ? 8 : 10;
acc = any = 0;
- if (base < 2 || base > 36)
+ if (base < 2)
goto noconv;
cutoff = ULONG_MAX / base;
cutlim = ULONG_MAX % base;
for ( ; ; c = *s++) {
- if (!isascii(c))
- break;
- if (isdigit(c))
- c -= '0';
- else if (isalpha(c))
+ if (isxdigit(c))
+ c = digittoint(c);
+ else if (isascii(c) && isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
diff --git a/lib/libc/stdlib/strtoull.c b/lib/libc/stdlib/strtoull.c
index e3db68c81537..15a097221188 100644
--- a/lib/libc/stdlib/strtoull.c
+++ b/lib/libc/stdlib/strtoull.c
@@ -52,13 +52,13 @@ unsigned long long
strtoull(nptr, endptr, base)
const char *nptr;
char **endptr;
- register int base;
+ int base;
{
- register const char *s;
- register unsigned long long acc;
- register unsigned char c;
- register unsigned long long cutoff;
- register int neg, any, cutlim;
+ const char *s;
+ unsigned long long acc;
+ unsigned char c;
+ unsigned long long cutoff;
+ int neg, any, cutlim;
/*
* See strtoq for comments as to the logic used.
@@ -84,17 +84,15 @@ strtoull(nptr, endptr, base)
if (base == 0)
base = c == '0' ? 8 : 10;
acc = any = 0;
- if (base < 2 || base > 36)
+ if (base < 2)
goto noconv;
cutoff = ULLONG_MAX / base;
cutlim = ULLONG_MAX % base;
for ( ; ; c = *s++) {
- if (!isascii(c))
- break;
- if (isdigit(c))
- c -= '0';
- else if (isalpha(c))
+ if (isxdigit(c))
+ c = digittoint(c);
+ else if (isascii(c) && isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
diff --git a/lib/libc/stdlib/strtouq.c b/lib/libc/stdlib/strtouq.c
index 1b59c4a7b92b..d5e992a0bede 100644
--- a/lib/libc/stdlib/strtouq.c
+++ b/lib/libc/stdlib/strtouq.c
@@ -43,9 +43,6 @@ static char sccsid[] = "@(#)strtouq.c 8.1 (Berkeley) 6/4/93";
/*
* Convert a string to an unsigned quad integer.
- *
- * Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
*/
u_quad_t
strtouq(nptr, endptr, base)