diff options
Diffstat (limited to 'apps/plugins/lua/strtol.c')
| -rw-r--r-- | apps/plugins/lua/strtol.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/apps/plugins/lua/strtol.c b/apps/plugins/lua/strtol.c new file mode 100644 index 0000000..184951b --- /dev/null +++ b/apps/plugins/lua/strtol.c @@ -0,0 +1,27 @@ +#include "rocklibc.h" + +extern unsigned long int strtoul(const char *ptr, char **endptr, int base); + +#define ABS_LONG_MIN 2147483648UL +long int strtol(const char *nptr, char **endptr, int base) +{ + int neg=0; + unsigned long int v; + const char*orig=nptr; + + while(isspace(*nptr)) nptr++; + + if (*nptr == '-' && isalnum(nptr[1])) { neg=-1; ++nptr; } + v=strtoul(nptr,endptr,base); + if (endptr && *endptr==nptr) *endptr=(char *)orig; + if (v>=ABS_LONG_MIN) { + if (v==ABS_LONG_MIN && neg) { + errno=0; + return v; + } + errno=ERANGE; + return (neg?LONG_MIN:LONG_MAX); + } + return (neg?-v:v); +} + |