2001-03-06 03:17:54 -05:00
|
|
|
/* public domain rewrite of strtol(3) */
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2001-03-06 03:17:54 -05:00
|
|
|
long
|
2005-10-21 21:28:00 -04:00
|
|
|
strtol(const char *nptr, char **endptr, int base)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-03-06 03:17:54 -05:00
|
|
|
long result;
|
2005-10-21 21:28:00 -04:00
|
|
|
const char *p = nptr;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
while (isspace(*p)) {
|
2001-03-06 03:17:54 -05:00
|
|
|
p++;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
if (*p == '-') {
|
2001-03-06 03:17:54 -05:00
|
|
|
p++;
|
|
|
|
result = -strtoul(p, endptr, base);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (*p == '+') p++;
|
|
|
|
result = strtoul(p, endptr, base);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2001-03-06 03:17:54 -05:00
|
|
|
if (endptr != 0 && *endptr == p) {
|
2005-10-21 21:28:00 -04:00
|
|
|
*endptr = (char *)nptr;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|