inttypes: add strtoimax and strtoumax

This commit is contained in:
Lephenixnoir 2021-05-20 16:05:20 +02:00
parent bc53e756a8
commit cc03641522
Signed by untrusted user: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
5 changed files with 47 additions and 1 deletions

View File

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

2
STATUS
View File

@ -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 <iso646.h>

View File

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

View File

@ -0,0 +1,16 @@
#include <inttypes.h>
#include <stdlib.h>
#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);
}

View File

@ -0,0 +1,16 @@
#include <inttypes.h>
#include <stdlib.h>
#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);
}