Commit 8f8cda9d authored by Alessandro Rubini's avatar Alessandro Rubini

libc-functions: hacked strtol and atoi

Such stuff is needed for command line parsing.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 59409d99
......@@ -7,6 +7,7 @@
#include <string.h>
extern void pp_puts(const char *s);
extern int atoi(const char *s);
extern uint32_t __div64_32(uint64_t *n, uint32_t base);
......
......@@ -69,3 +69,26 @@ char *strcpy(char *s1, const char *s2)
;
return s1;
}
/* for strtol even uClibc is too heavy. Let's rewrite some hack */
long int strtol(const char *s, char **end, int base)
{
long res = 0;
if (!base)
base = 10;
while (*s) {
if (end)
*end = (void *)s;
/* we only use it for cmdline: avoid alpha digits */
if (base > 10 || *s < '0' || *s >= '0' + base) {
return res;
}
res = res * base + *(s++) - '0';
}
return res;
}
int atoi(const char *s)
{
return strtol(s, NULL, 10);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment