diff --git a/CMakeLists.txt b/CMakeLists.txt index 79f43ff..523ee83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,9 @@ set(SOURCES src/libc/stdio/printf.c # stdlib src/libc/stdlib/abs.c + src/libc/stdlib/atoi.c + src/libc/stdlib/atol.c + src/libc/stdlib/atoll.c src/libc/stdlib/calloc.c src/libc/stdlib/div.c src/libc/stdlib/labs.c diff --git a/STATUS b/STATUS index a7f1d24..3238b46 100644 --- a/STATUS +++ b/STATUS @@ -98,7 +98,7 @@ DONE: Function/symbol/macro is defined, builds, links, and is tested 7.20 7.20.1.1 atof: TODO - 7.20.1.2 atoi, atol, atoll: TODO + 7.20.1.2 atoi, atol, atoll: DONE 7.20.1.3 strtod, strtof, strtold: TODO 7.20.1.4 strtol, strtoul, strtoll, strtoull: DONE 7.20.2 Pseudo-random sequence generation functions: TODO diff --git a/include/stdlib.h b/include/stdlib.h index db5cc60..63e8d91 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -63,6 +63,17 @@ div_t div(int __num, int __denom); ldiv_t ldiv(long int __num, long int __denom); lldiv_t lldiv(long long int __num, long long int __denom); +/* Simplified numeric conversion functions. */ + +/* ASCII to int. */ +extern int atoi(char const *__ptr); + +/* ASCII to long int. */ +extern long int atol(char const *__ptr); + +/* ASCII to long long int. */ +extern long long int atoll(char const *__ptr); + /* Numeric conversion functions. */ /* Parse a long int from a string. */ diff --git a/src/libc/stdlib/atoi.c b/src/libc/stdlib/atoi.c new file mode 100644 index 0000000..1fe38c8 --- /dev/null +++ b/src/libc/stdlib/atoi.c @@ -0,0 +1,6 @@ +#include + +int atoi(char const *ptr) +{ + return (int)strtol(ptr, NULL, 10); +} diff --git a/src/libc/stdlib/atol.c b/src/libc/stdlib/atol.c new file mode 100644 index 0000000..6195e5a --- /dev/null +++ b/src/libc/stdlib/atol.c @@ -0,0 +1,6 @@ +#include + +long int atol(char const *ptr) +{ + return strtol(ptr, NULL, 10); +} diff --git a/src/libc/stdlib/atoll.c b/src/libc/stdlib/atoll.c new file mode 100644 index 0000000..54816e3 --- /dev/null +++ b/src/libc/stdlib/atoll.c @@ -0,0 +1,6 @@ +#include + +long long int atoll(char const *ptr) +{ + return strtoll(ptr, NULL, 10); +}