diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libc/stdlib/strtoll.c (renamed from src/lib/libc/stdlib/strtoq.c) | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/src/lib/libc/stdlib/strtoq.c b/src/lib/libc/stdlib/strtoll.c index 44aabd73f0..b0eb6d198c 100644 --- a/src/lib/libc/stdlib/strtoq.c +++ b/src/lib/libc/stdlib/strtoll.c | |||
@@ -32,7 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | static char rcsid[] = "$OpenBSD: strtoq.c,v 1.4 1996/08/19 08:33:52 tholo Exp $"; | 35 | static const char rcsid[] = "$OpenBSD: strtoll.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: strtoq.c,v 1.4 1996/08/19 08:33:52 tholo Exp $" | |||
43 | #include <stdlib.h> | 43 | #include <stdlib.h> |
44 | 44 | ||
45 | /* | 45 | /* |
46 | * Convert a string to a quad integer. | 46 | * Convert a string to a 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 | */ |
51 | quad_t | 51 | long long |
52 | strtoq(nptr, endptr, base) | 52 | strtoll(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 quad_t acc, cutoff; | 58 | 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 | * Skip white space and pick up leading +/- sign if any. | 63 | * Skip white space and pick up leading +/- sign if any. |
@@ -92,7 +92,7 @@ strtoq(nptr, endptr, base) | |||
92 | * followed by a legal input character, is too big. One that | 92 | * followed by a legal input character, is too big. One that |
93 | * is equal to this value may be valid or not; the limit | 93 | * is equal to this value may be valid or not; the limit |
94 | * between valid and invalid numbers is then based on the last | 94 | * between valid and invalid numbers is then based on the last |
95 | * digit. For instance, if the range for quads is | 95 | * digit. For instance, if the range for long longs is |
96 | * [-9223372036854775808..9223372036854775807] and the input base | 96 | * [-9223372036854775808..9223372036854775807] and the input base |
97 | * is 10, cutoff will be set to 922337203685477580 and cutlim to | 97 | * is 10, cutoff will be set to 922337203685477580 and cutlim to |
98 | * either 7 (neg==0) or 8 (neg==1), meaning that if we have | 98 | * either 7 (neg==0) or 8 (neg==1), meaning that if we have |
@@ -103,7 +103,7 @@ strtoq(nptr, endptr, base) | |||
103 | * Set any if any `digits' consumed; make it negative to indicate | 103 | * Set any if any `digits' consumed; make it negative to indicate |
104 | * overflow. | 104 | * overflow. |
105 | */ | 105 | */ |
106 | cutoff = neg ? QUAD_MIN : QUAD_MAX; | 106 | cutoff = neg ? LLONG_MIN : LLONG_MAX; |
107 | cutlim = cutoff % base; | 107 | cutlim = cutoff % base; |
108 | cutoff /= base; | 108 | cutoff /= base; |
109 | if (neg) { | 109 | if (neg) { |
@@ -125,9 +125,9 @@ strtoq(nptr, endptr, base) | |||
125 | if (any < 0) | 125 | if (any < 0) |
126 | continue; | 126 | continue; |
127 | if (neg) { | 127 | if (neg) { |
128 | if (acc < cutoff || acc == cutoff && c > cutlim) { | 128 | if (acc < cutoff || (acc == cutoff && c > cutlim)) { |
129 | any = -1; | 129 | any = -1; |
130 | acc = QUAD_MIN; | 130 | acc = LLONG_MIN; |
131 | errno = ERANGE; | 131 | errno = ERANGE; |
132 | } else { | 132 | } else { |
133 | any = 1; | 133 | any = 1; |
@@ -135,9 +135,9 @@ strtoq(nptr, endptr, base) | |||
135 | acc -= c; | 135 | acc -= c; |
136 | } | 136 | } |
137 | } else { | 137 | } else { |
138 | if (acc > cutoff || acc == cutoff && c > cutlim) { | 138 | if (acc > cutoff || (acc == cutoff && c > cutlim)) { |
139 | any = -1; | 139 | any = -1; |
140 | acc = QUAD_MAX; | 140 | acc = LLONG_MAX; |
141 | errno = ERANGE; | 141 | errno = ERANGE; |
142 | } else { | 142 | } else { |
143 | any = 1; | 143 | any = 1; |
@@ -150,3 +150,17 @@ strtoq(nptr, endptr, base) | |||
150 | *endptr = (char *) (any ? s - 1 : nptr); | 150 | *endptr = (char *) (any ? s - 1 : nptr); |
151 | return (acc); | 151 | return (acc); |
152 | } | 152 | } |
153 | |||
154 | #ifdef __weak_alias | ||
155 | __weak_alias(strtoq, strtoll); | ||
156 | #else | ||
157 | quad_t | ||
158 | strtoq(nptr, endptr, base) | ||
159 | const char *nptr; | ||
160 | char **endptr; | ||
161 | int base; | ||
162 | { | ||
163 | |||
164 | return ((quad_t)strtoll(nptr, endptr, base); | ||
165 | } | ||
166 | #endif | ||