ea463469859d4fa55493968702c612b7dc62bccf
5 * Convert a string to an unsigned long integer.
7 * Ignores `locale' stuff. Assumes that the upper and lower case
8 * alphabets and digits are each contiguous.
13 strtoul(const char *nptr
, char **endptr
, int base
)
19 int neg
= 0, any
, cutlim
;
22 * See strtol for comments as to the logic used.
34 if ((base
== 0 || base
== 16) &&
35 c
== '0' && (*s
== 'x' || *s
== 'X'))
42 base
= c
== '0' ? 8 : 10;
43 cutoff
= (unsigned long)ULONG_MAX
/ (unsigned long)base
;
44 cutlim
= (unsigned long)ULONG_MAX
% (unsigned long)base
;
45 for (acc
= 0, any
= 0;; c
= *s
++)
50 c
-= isupper(c
) ? 'A' - 10 : 'a' - 10;
55 if (any
< 0 || acc
> cutoff
|| (acc
== cutoff
&& c
> cutlim
))
73 *endptr
= any
? (char *)((size_t)(s
- 1)) : (char *)((size_t)nptr
);