Skip to content

Commit 68ecb23

Browse files
committed
Simplifying and fixing atoi / atol.
1 parent 396a5ce commit 68ecb23

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

libc/LIB.status

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Stdlib:
44
What should stdlib contain, and current status.
55

66
atof - ok, inlined, bound to sscanf
7-
atoi - ok, inlined, bound to sscanf, will read hex and octal
8-
atol - ok, inlined, bound to sscanf, will read hex and octal
7+
atoi - ok, inlined, bound to strtol
8+
atol - ok, inlined, bound to strtol
99
strtod - missing
1010
strtof - missing
1111
strtold - missing (do we want to support long double anyway?)

libc/include/stdlib.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ int rand_r(unsigned int * seed);
2121
static __inline__ int rand(void) { return rand_r(&_seed); }
2222
static __inline__ void srand(unsigned int seed) { _seed = seed * 3835238167UL; }
2323

24-
static __inline__ double atof(const char * str) { double r = 0; sscanf(str, "%lf", &r); return r; }
25-
static __inline__ int atoi(const char * str) { int i; sscanf(str, "%i", &i); return i; }
26-
static __inline__ int atol(const char * str) { long l; sscanf(str, "%li", &l); return l; }
27-
2824
long int strtol(const char * nptr, char ** endptr, int base);
2925

30-
END_DECL
26+
static __inline__ double atof(const char * str) { double r = 0; sscanf(str, "%lf", &r); return r; }
27+
static __inline__ int atoi(const char *str) { return strtol(str, NULL, 10); }
28+
static __inline__ long atol(const char * str) { return strtol(str, NULL, 10); }
3129

30+
END_DECL

0 commit comments

Comments
 (0)