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