1 /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
2 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
6 /* constants used in Solaris */
7 #define LLONG_MIN -9223372036854775807L-1L
8 #define LLONG_MAX 9223372036854775807L
9 #define ULLONG_MAX 18446744073709551615UL
12 strtoll(const char *nptr
, char **endptr
, int base
)
18 int neg
= 0, any
, cutlim
;
21 * See strtol for comments as to the logic used.
33 if ((base
== 0 || base
== 16) &&
34 c
== '0' && (*s
== 'x' || *s
== 'X'))
41 base
= c
== '0' ? 8 : 10;
43 /* to prevent overflow, we take max-1 and add 1 after division */
44 cutoff
= neg
? -(LLONG_MIN
+1) : LLONG_MAX
-1;
45 cutlim
= cutoff
% base
;
52 for (acc
= 0, any
= 0;; c
= *s
++)
57 c
-= isupper(c
) ? 'A' - 10 : 'a' - 10;
62 if (any
< 0 || acc
> cutoff
|| (acc
== cutoff
&& c
> cutlim
))
73 acc
= neg
? LLONG_MIN
: LLONG_MAX
;
79 *endptr
= any
? (char *)s
- 1 : (char *)nptr
;