stdlib: add atoi, atol and atoll

This commit is contained in:
Lephenixnoir 2021-05-20 11:11:24 +02:00
parent 06f975f75c
commit ade01b532e
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
6 changed files with 33 additions and 1 deletions

View file

@ -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

2
STATUS
View file

@ -98,7 +98,7 @@ DONE: Function/symbol/macro is defined, builds, links, and is tested
7.20 <stdlib.h>
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

View file

@ -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. */

6
src/libc/stdlib/atoi.c Normal file
View file

@ -0,0 +1,6 @@
#include <stdlib.h>
int atoi(char const *ptr)
{
return (int)strtol(ptr, NULL, 10);
}

6
src/libc/stdlib/atol.c Normal file
View file

@ -0,0 +1,6 @@
#include <stdlib.h>
long int atol(char const *ptr)
{
return strtol(ptr, NULL, 10);
}

6
src/libc/stdlib/atoll.c Normal file
View file

@ -0,0 +1,6 @@
#include <stdlib.h>
long long int atoll(char const *ptr)
{
return strtoll(ptr, NULL, 10);
}