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>
10 * Convert a string to an unsigned long integer.
12 * Ignores `locale' stuff. Assumes that the upper and lower case
13 * alphabets and digits are each contiguous.
16 strtoull(const char *nptr
, char **endptr
, int base
)
22 int neg
= 0, any
, cutlim
;
25 * See strtol for comments as to the logic used.
37 if ((base
== 0 || base
== 16) &&
38 c
== '0' && (*s
== 'x' || *s
== 'X'))
45 base
= c
== '0' ? 8 : 10;
46 cutoff
= (unsigned long)ULONG_MAX
/ base
;
47 cutlim
= (unsigned long)ULONG_MAX
% base
;
48 for (acc
= 0, any
= 0;; c
= *s
++)
53 c
-= isupper(c
) ? 'A' - 10 : 'a' - 10;
58 if (any
< 0 || acc
> cutoff
|| (acc
== cutoff
&& c
> cutlim
))
74 *endptr
= any
? (char *)s
- 1 : (char *)nptr
;