1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/missing/strtol.c

30 lines
448 B
C
Raw Normal View History

/* public domain rewrite of strtol(3) */
#include <ctype.h>
long
strtol(nptr, endptr, base)
char *nptr;
char **endptr;
int base;
{
long result;
char *p = nptr;
while (isspace(*p)) {
p++;
}
if (*p == '-') {
p++;
result = -strtoul(p, endptr, base);
}
else {
if (*p == '+') p++;
result = strtoul(p, endptr, base);
}
if (endptr != 0 && *endptr == p) {
*endptr = nptr;
}
return result;
}