1 /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
2 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
4 #include <msvcrt/ctype.h>
5 #include <msvcrt/errno.h>
6 #include <msvcrt/stdlib.h>
7 //#include <msvcrt/unconst.h>
9 /* constants used in Solaris */
10 #define LLONG_MIN -9223372036854775807L-1L
11 #define LLONG_MAX 9223372036854775807L
12 #define ULLONG_MAX 18446744073709551615UL
15 strtoll(const char *nptr, char **endptr, int base)
21 int neg = 0, any, cutlim;
24 * See strtol for comments as to the logic used.
36 if ((base == 0 || base == 16) &&
37 c == '0' && (*s == 'x' || *s == 'X'))
44 base = c == '0' ? 8 : 10;
46 /* to prevent overflow, we take max-1 and add 1 after division */
47 cutoff = neg ? -(LLONG_MIN+1) : LLONG_MAX-1;
48 cutlim = cutoff % base;
55 for (acc = 0, any = 0;; c = *s++)
60 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
65 if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
76 acc = neg ? LLONG_MIN : LLONG_MAX;
82 *endptr = any ? (char *)s - 1 : (char *)nptr;