diff --git a/CMakeLists.txt b/CMakeLists.txt index a796024..e049d27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,8 @@ set(SOURCES # inttypes src/libc/inttypes/imaxabs.c src/libc/inttypes/imaxdiv.c + src/libc/inttypes/strtoimax.c + src/libc/inttypes/strtoumax.c # locale src/libc/locale/setlocale.c src/libc/locale/localeconv.c diff --git a/STATUS b/STATUS index db0b572..a1d50cf 100644 --- a/STATUS +++ b/STATUS @@ -47,7 +47,7 @@ DONE: Function/symbol/macro is defined, builds, links, and is tested 7.8.1 SCN* macros: LDEPS(*scanf) 7.8.2.1 imaxabs: DONE 7.8.2.2 imaxdiv: DONE - 7.8.2.3 strotimax strtoumax: TODO + 7.8.2.3 strtoimax strtoumax: DONE 7.8.2.4 wcstoimax wcstoumax: TODO 7.9 diff --git a/include/inttypes.h b/include/inttypes.h index 076b3f0..8e568f4 100644 --- a/include/inttypes.h +++ b/include/inttypes.h @@ -243,4 +243,16 @@ extern intmax_t imaxabs(intmax_t __j); extern imaxdiv_t imaxdiv(intmax_t __num, intmax_t __denom); #define imaxdiv lldiv +/* Parse an intmax_t from string. */ +extern intmax_t strtoimax( + char const * restrict __ptr, + char ** restrict __endptr, + int __base); + +/* Parse an uintmax_t from string. */ +extern uintmax_t strtoumax( + char const * restrict __ptr, + char ** restrict __endptr, + int __base); + #endif /*__INTTYPES_H__*/ diff --git a/src/libc/inttypes/strtoimax.c b/src/libc/inttypes/strtoimax.c new file mode 100644 index 0000000..2a948b9 --- /dev/null +++ b/src/libc/inttypes/strtoimax.c @@ -0,0 +1,16 @@ +#include +#include + +#if __INTMAX_WIDTH__ == __LONG_WIDTH__ +# define __strtoimax strtol +#elif __INTMAX_WIDTH__ == __LONG_LONG_WIDTH__ +# define __strtoimax strtoll +#else +# error How is intmax_t neither long nor long long? +#endif + +intmax_t strtoimax(char const * restrict ptr, char ** restrict endptr, + int base) +{ + return __strtoimax(ptr, endptr, base); +} diff --git a/src/libc/inttypes/strtoumax.c b/src/libc/inttypes/strtoumax.c new file mode 100644 index 0000000..6a359cf --- /dev/null +++ b/src/libc/inttypes/strtoumax.c @@ -0,0 +1,16 @@ +#include +#include + +#if __INTMAX_WIDTH__ == __LONG_WIDTH__ +# define __strtoumax strtoul +#elif __INTMAX_WIDTH__ == __LONG_LONG_WIDTH__ +# define __strtoumax strtoull +#else +# error How is uintmax_t neither unsigned long nor unsigned long long? +#endif + +uintmax_t strtoumax(char const * restrict ptr, char ** restrict endptr, + int base) +{ + return __strtoumax(ptr, endptr, base); +}