From 4c0440cb8652801c1c3750a474f7ddbb17897cdf Mon Sep 17 00:00:00 2001 From: "David E. O'Brien" Date: Tue, 27 Feb 2001 13:33:07 +0000 Subject: Impliment the ISO-C99 strto[u]ll() and rewrite strto[u]q() in terms of it. --- lib/libc/stdlib/strtoll.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'lib/libc/stdlib/strtoll.c') diff --git a/lib/libc/stdlib/strtoll.c b/lib/libc/stdlib/strtoll.c index f84e030531bb..b7a75903e5e7 100644 --- a/lib/libc/stdlib/strtoll.c +++ b/lib/libc/stdlib/strtoll.c @@ -35,6 +35,11 @@ static char sccsid[] = "@(#)strtoq.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#ifndef lint +static const char rcsid[] = + "$FreeBSD$"; +#endif + #include #include @@ -43,21 +48,21 @@ static char sccsid[] = "@(#)strtoq.c 8.1 (Berkeley) 6/4/93"; #include /* - * Convert a string to a quad integer. + * Convert a string to a long long integer. * * Ignores `locale' stuff. Assumes that the upper and lower case * alphabets and digits are each contiguous. */ -quad_t -strtoq(nptr, endptr, base) +long long +strtoll(nptr, endptr, base) const char *nptr; char **endptr; register int base; { register const char *s; - register u_quad_t acc; + register unsigned long long acc; register unsigned char c; - register u_quad_t qbase, cutoff; + register unsigned long long qbase, cutoff; register int neg, any, cutlim; /* @@ -105,7 +110,8 @@ strtoq(nptr, endptr, base) * overflow. */ qbase = (unsigned)base; - cutoff = neg ? (u_quad_t)-(QUAD_MIN + QUAD_MAX) + QUAD_MAX : QUAD_MAX; + cutoff = neg ? (unsigned long long)-(LLONG_MIN + LLONG_MAX) + LLONG_MAX + : LLONG_MAX; cutlim = cutoff % qbase; cutoff /= qbase; for (acc = 0, any = 0;; c = *s++) { @@ -128,7 +134,7 @@ strtoq(nptr, endptr, base) } } if (any < 0) { - acc = neg ? QUAD_MIN : QUAD_MAX; + acc = neg ? LLONG_MIN : LLONG_MAX; errno = ERANGE; } else if (neg) acc = -acc; -- cgit v1.2.3