35 #include <sys/cdefs.h>
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/ctype.h>
41 #include <sys/limits.h>
59 int neg = 0, any, cutlim;
72 if ((base == 0 || base == 16) &&
73 c ==
'0' && (*s ==
'x' || *s ==
'X')) {
79 base = c ==
'0' ? 8 : 10;
80 cutoff = (
unsigned long)ULONG_MAX / (
unsigned long)base;
81 cutlim = (
unsigned long)ULONG_MAX % (
unsigned long)base;
82 for (acc = 0, any = 0;; c = *s++) {
88 c -= isupper(c) ?
'A' - 10 :
'a' - 10;
93 if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
106 *endptr = __DECONST(
char *, any ? s - 1 : nptr);
unsigned long strtoul(char *nptr, char **endptr, int base) const