79long strtol(
const char* nptr,
char** endptr,
int base)
90 if(base < 0 || base > 36)
96 *endptr = (
char*)(uintptr_t)nptr;
122 if((base == 0 || base == 16) && c ==
'0' && (*s ==
'x' || *s ==
'X'))
128 else if((base == 0 || base == 2) && c ==
'0' && (*s ==
'b' || *s ==
'B'))
137 base = c ==
'0' ? 8 : 10;
157 cutoff = neg ? -(
unsigned long)LONG_MIN : LONG_MAX;
158 cutlim = (int)(cutoff % (
unsigned long)base);
159 cutoff /= (
unsigned long)base;
161 for(acc = 0, any = 0;; c = *s++)
169 c -= isupper(c) ?
'A' - 10 :
'a' - 10;
181 if(any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
188 acc *= (
unsigned long)base;
189 acc += (
unsigned long)c;
195 acc = neg ? (
unsigned long)LONG_MIN : (unsigned long)LONG_MAX;
205 *endptr = (
char*)(uintptr_t)(any ? s - 1 : nptr);