79unsigned long strtoul(
const char* nptr,
char** endptr,
int base)
107 if((base == 0 || base == 16) && c ==
'0' && (*s ==
'x' || *s ==
'X'))
113 else if((base == 0 || base == 2) && c ==
'0' && (*s ==
'b' || *s ==
'B'))
122 base = c ==
'0' ? 8 : 10;
125 cutoff = (
unsigned long)ULONG_MAX / (
unsigned long)base;
126 cutlim = (int)((
unsigned long)ULONG_MAX % (
unsigned long)base);
128 for(acc = 0, any = 0;; c = *s++)
136 c -= isupper(c) ?
'A' - 10 :
'a' - 10;
146 if(any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
153 acc *= (
unsigned long)base;
154 acc += (
unsigned long)c;
170 *endptr = (
char*)(uintptr_t)(any ? s - 1 : nptr);