
1: /* public domain rewrite of strtol(3) */ 2: 3: #include <ctype.h> 4: 5: long 6: strtol(const char *nptr, char **endptr, int base) 7: { 8: long result; 9: const char *p = nptr; 10: 11: while (isspace(*p)) { 12: p++; 13: } 14: if (*p == '-') { 15: p++; 16: result = -strtoul(p, endptr, base); 17: } 18: else { 19: if (*p == '+') p++; 20: result = strtoul(p, endptr, base); 21: } 22: if (endptr != 0 && *endptr == p) { 23: *endptr = (char *)nptr; 24: } 25: return result; 26: }