summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/strtoull.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libc/stdlib/strtoull.c (renamed from src/lib/libc/stdlib/strtouq.c)42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/lib/libc/stdlib/strtouq.c b/src/lib/libc/stdlib/strtoull.c
index 1f29a22f33..7b4dd56c01 100644
--- a/src/lib/libc/stdlib/strtouq.c
+++ b/src/lib/libc/stdlib/strtoull.c
@@ -32,7 +32,7 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35static char rcsid[] = "$OpenBSD: strtouq.c,v 1.4 1996/08/19 08:33:53 tholo Exp $"; 35static const char rcsid[] = "$OpenBSD: strtoull.c,v 1.1 2002/06/29 00:20:11 millert Exp $";
36#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
37 37
38#include <sys/types.h> 38#include <sys/types.h>
@@ -43,21 +43,21 @@ static char rcsid[] = "$OpenBSD: strtouq.c,v 1.4 1996/08/19 08:33:53 tholo Exp $
43#include <stdlib.h> 43#include <stdlib.h>
44 44
45/* 45/*
46 * Convert a string to an unsigned quad integer. 46 * Convert a string to an unsigned long long.
47 * 47 *
48 * Ignores `locale' stuff. Assumes that the upper and lower case 48 * Ignores `locale' stuff. Assumes that the upper and lower case
49 * alphabets and digits are each contiguous. 49 * alphabets and digits are each contiguous.
50 */ 50 */
51u_quad_t 51unsigned long long
52strtouq(nptr, endptr, base) 52strtoull(nptr, endptr, base)
53 const char *nptr; 53 const char *nptr;
54 char **endptr; 54 char **endptr;
55 register int base; 55 int base;
56{ 56{
57 register const char *s; 57 const char *s;
58 register u_quad_t acc, cutoff; 58 unsigned long long acc, cutoff;
59 register int c; 59 int c;
60 register int neg, any, cutlim; 60 int neg, any, cutlim;
61 61
62 /* 62 /*
63 * See strtoq for comments as to the logic used. 63 * See strtoq for comments as to the logic used.
@@ -83,8 +83,8 @@ strtouq(nptr, endptr, base)
83 if (base == 0) 83 if (base == 0)
84 base = c == '0' ? 8 : 10; 84 base = c == '0' ? 8 : 10;
85 85
86 cutoff = UQUAD_MAX / (u_quad_t)base; 86 cutoff = ULLONG_MAX / (unsigned long long)base;
87 cutlim = UQUAD_MAX % (u_quad_t)base; 87 cutlim = ULLONG_MAX % (unsigned long long)base;
88 for (acc = 0, any = 0;; c = (unsigned char) *s++) { 88 for (acc = 0, any = 0;; c = (unsigned char) *s++) {
89 if (isdigit(c)) 89 if (isdigit(c))
90 c -= '0'; 90 c -= '0';
@@ -96,13 +96,13 @@ strtouq(nptr, endptr, base)
96 break; 96 break;
97 if (any < 0) 97 if (any < 0)
98 continue; 98 continue;
99 if (acc > cutoff || acc == cutoff && c > cutlim) { 99 if (acc > cutoff || (acc == cutoff && c > cutlim)) {
100 any = -1; 100 any = -1;
101 acc = UQUAD_MAX; 101 acc = ULLONG_MAX;
102 errno = ERANGE; 102 errno = ERANGE;
103 } else { 103 } else {
104 any = 1; 104 any = 1;
105 acc *= (u_quad_t)base; 105 acc *= (unsigned long long)base;
106 acc += c; 106 acc += c;
107 } 107 }
108 } 108 }
@@ -112,3 +112,17 @@ strtouq(nptr, endptr, base)
112 *endptr = (char *) (any ? s - 1 : nptr); 112 *endptr = (char *) (any ? s - 1 : nptr);
113 return (acc); 113 return (acc);
114} 114}
115
116#ifdef __weak_alias
117__weak_alias(strtouq, strtoull);
118#else
119u_quad_t
120strtouq(nptr, endptr, base)
121 const char *nptr;
122 char **endptr;
123 int base;
124{
125
126 return ((u_quad_t)strtoull(nptr, endptr, base);
127}
128#endif