43#include <sys/limits.h>
52strtol(
const char *nptr,
char **endptr,
int base)
58 int neg = 0, any, cutlim;
73 if ((base == 0 || base == 16) &&
74 c ==
'0' && (*s ==
'x' || *s ==
'X')) {
80 base =
c ==
'0' ? 8 : 10;
99 cutoff = neg ? -(
unsigned long)LONG_MIN : LONG_MAX;
100 cutlim = cutoff % (
unsigned long)base;
101 cutoff /= (
unsigned long)base;
102 for (acc = 0, any = 0;;
c = *s++) {
108 c -= isupper(
c) ?
'A' - 10 :
'a' - 10;
113 if (any < 0 || acc > cutoff || (acc == cutoff &&
c > cutlim))
122 acc = neg ? LONG_MIN : LONG_MAX;
126 *endptr = __DECONST(
char *, any ? s - 1 : nptr);
long strtol(const char *nptr, char **endptr, int base)