From e0c0c4749d7d5e4c0973293f69f69a98a6c615fd Mon Sep 17 00:00:00 2001 From: mycroft Date: Wed, 20 Dec 1995 23:14:48 +0000 Subject: [PATCH] Minor cleanup. --- lib/libc/stdlib/strtol.c | 18 +++++++++++------- lib/libc/stdlib/strtoq.c | 13 ++++++------- lib/libc/stdlib/strtoul.c | 23 ++++++++++++++--------- lib/libc/stdlib/strtouq.c | 16 ++++++++-------- 4 files changed, 39 insertions(+), 31 deletions(-) diff --git a/lib/libc/stdlib/strtol.c b/lib/libc/stdlib/strtol.c index 1ad96326e05b..b5f6fd88f778 100644 --- a/lib/libc/stdlib/strtol.c +++ b/lib/libc/stdlib/strtol.c @@ -33,12 +33,12 @@ #if defined(LIBC_SCCS) && !defined(lint) /*static char *sccsid = "from: @(#)strtol.c 5.4 (Berkeley) 2/23/91";*/ -static char *rcsid = "$Id: strtol.c,v 1.4 1993/08/26 00:48:14 jtc Exp $"; +static char *rcsid = "$Id: strtol.c,v 1.5 1995/12/20 23:14:48 mycroft Exp $"; #endif /* LIBC_SCCS and not lint */ -#include #include #include +#include #include @@ -54,25 +54,29 @@ strtol(nptr, endptr, base) char **endptr; register int base; { - register const char *s = nptr; + register const char *s; register unsigned long acc; register int c; register unsigned long cutoff; - register int neg = 0, any, cutlim; + register int neg, any, cutlim; /* * Skip white space and pick up leading +/- sign if any. * If base is 0, allow 0x for hex and 0 for octal, else * assume decimal; if base is already 16, allow 0x. */ + s = nptr; do { c = *s++; } while (isspace(c)); if (c == '-') { neg = 1; c = *s++; - } else if (c == '+') - c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) { c = s[1]; @@ -115,7 +119,7 @@ strtol(nptr, endptr, base) any = -1; else { any = 1; - acc *= base; + acc *= (unsigned long)base; acc += c; } } diff --git a/lib/libc/stdlib/strtoq.c b/lib/libc/stdlib/strtoq.c index fc559e9d7f08..33603ae672b8 100644 --- a/lib/libc/stdlib/strtoq.c +++ b/lib/libc/stdlib/strtoq.c @@ -37,9 +37,9 @@ static char sccsid[] = "@(#)strtoq.c 5.1 (Berkeley) 6/26/92"; #include -#include -#include #include +#include +#include #include /* @@ -57,7 +57,7 @@ strtoq(nptr, endptr, base) register const char *s; register u_quad_t acc; register int c; - register u_quad_t qbase, cutoff; + register u_quad_t cutoff; register int neg, any, cutlim; /* @@ -104,10 +104,9 @@ strtoq(nptr, endptr, base) * Set any if any `digits' consumed; make it negative to indicate * overflow. */ - qbase = (unsigned)base; cutoff = neg ? -(u_quad_t)QUAD_MIN : QUAD_MAX; - cutlim = cutoff % qbase; - cutoff /= qbase; + cutlim = cutoff % (u_quad_t)base; + cutoff /= (u_quad_t)base; for (acc = 0, any = 0;; c = *s++) { if (isdigit(c)) c -= '0'; @@ -121,7 +120,7 @@ strtoq(nptr, endptr, base) any = -1; else { any = 1; - acc *= qbase; + acc *= (u_quad_t)base; acc += c; } } diff --git a/lib/libc/stdlib/strtoul.c b/lib/libc/stdlib/strtoul.c index bd2f9b97ae96..e86712d198ff 100644 --- a/lib/libc/stdlib/strtoul.c +++ b/lib/libc/stdlib/strtoul.c @@ -33,12 +33,12 @@ #if defined(LIBC_SCCS) && !defined(lint) /*static char *sccsid = "from: @(#)strtoul.c 5.3 (Berkeley) 2/23/91";*/ -static char *rcsid = "$Id: strtoul.c,v 1.4 1993/08/26 00:48:14 jtc Exp $"; +static char *rcsid = "$Id: strtoul.c,v 1.5 1995/12/20 23:14:50 mycroft Exp $"; #endif /* LIBC_SCCS and not lint */ -#include #include #include +#include #include /* @@ -53,23 +53,27 @@ strtoul(nptr, endptr, base) char **endptr; register int base; { - register const char *s = nptr; + register const char *s; register unsigned long acc; register int c; register unsigned long cutoff; - register int neg = 0, any, cutlim; + register int neg, any, cutlim; /* * See strtol for comments as to the logic used. */ + s = nptr; do { c = *s++; } while (isspace(c)); if (c == '-') { neg = 1; c = *s++; - } else if (c == '+') - c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) { c = s[1]; @@ -78,8 +82,9 @@ strtoul(nptr, endptr, base) } if (base == 0) base = c == '0' ? 8 : 10; - cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; - cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; + + cutoff = ULONG_MAX / (unsigned long)base; + cutlim = ULONG_MAX % (unsigned long)base; for (acc = 0, any = 0;; c = *s++) { if (isdigit(c)) c -= '0'; @@ -93,7 +98,7 @@ strtoul(nptr, endptr, base) any = -1; else { any = 1; - acc *= base; + acc *= (unsigned long)base; acc += c; } } diff --git a/lib/libc/stdlib/strtouq.c b/lib/libc/stdlib/strtouq.c index cc647d8d2893..2bba44dc274c 100644 --- a/lib/libc/stdlib/strtouq.c +++ b/lib/libc/stdlib/strtouq.c @@ -37,9 +37,9 @@ static char sccsid[] = "@(#)strtouq.c 5.1 (Berkeley) 6/26/92"; #include -#include -#include #include +#include +#include #include /* @@ -54,10 +54,10 @@ strtouq(nptr, endptr, base) char **endptr; register int base; { - register const char *s = nptr; + register const char *s; register u_quad_t acc; register int c; - register u_quad_t qbase, cutoff; + register u_quad_t cutoff; register int neg, any, cutlim; /* @@ -83,9 +83,9 @@ strtouq(nptr, endptr, base) } if (base == 0) base = c == '0' ? 8 : 10; - qbase = (unsigned)base; - cutoff = (u_quad_t)UQUAD_MAX / qbase; - cutlim = (u_quad_t)UQUAD_MAX % qbase; + + cutoff = UQUAD_MAX / (u_quad_t)base; + cutlim = UQUAD_MAX % (u_quad_t)base; for (acc = 0, any = 0;; c = *s++) { if (isdigit(c)) c -= '0'; @@ -99,7 +99,7 @@ strtouq(nptr, endptr, base) any = -1; else { any = 1; - acc *= qbase; + acc *= (u_quad_t)base; acc += c; } }