Minor cleanup.
This commit is contained in:
parent
628076bc54
commit
e0c0c4749d
|
@ -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 <limits.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,9 +37,9 @@ static char sccsid[] = "@(#)strtoq.c 5.1 (Berkeley) 6/26/92";
|
|||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <limits.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,9 +37,9 @@ static char sccsid[] = "@(#)strtouq.c 5.1 (Berkeley) 6/26/92";
|
|||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue