rockbox/apps/plugins/lua/strtol.c
Maurus Cuelenaere cf87597226 Commit FS#9174: Lua scripting language by Dan Everton
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21020 a1c6a512-1295-4272-9138-f99709370657
2009-05-21 19:01:41 +00:00

27 lines
611 B
C

#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);
}