diff --git a/system/include/compat/xlocale.h b/system/include/compat/xlocale.h new file mode 100644 index 0000000000000..dd29382591efd --- /dev/null +++ b/system/include/compat/xlocale.h @@ -0,0 +1,18 @@ +#ifndef _COMPAT_XLOCALE_H_ +#define _COMPAT_XLOCALE_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +long long strtoll_l(const char *start, char **end, int base, locale_t loc); +unsigned long long strtoull_l(const char *start, char **end, int base, locale_t loc); +long double strtold_l(const char *start, char **end, locale_t loc); + +#ifdef __cplusplus +} +#endif + +#endif /* _COMPAT_XLOCALE_H_ */ diff --git a/system/lib/libc/compat/strtol_l.c b/system/lib/libc/compat/strtol_l.c new file mode 100644 index 0000000000000..58b46186941c2 --- /dev/null +++ b/system/lib/libc/compat/strtol_l.c @@ -0,0 +1,22 @@ +#include +#include + +unsigned long long strtoull_l(const char *restrict s, char **restrict p, int base, locale_t loc) +{ + return strtoull(s, p, base); +} + +long long strtoll_l(const char *restrict s, char **restrict p, int base, locale_t loc) +{ + return strtoll(s, p, base); +} + +unsigned long strtoul_l(const char *restrict s, char **restrict p, int base, locale_t loc) +{ + return strtoul(s, p, base); +} + +long strtol_l(const char *restrict s, char **restrict p, int base, locale_t loc) +{ + return strtol(s, p, base); +} diff --git a/tests/other/test_xlocale.c b/tests/other/test_xlocale.c new file mode 100644 index 0000000000000..ebe2ec6d98d64 --- /dev/null +++ b/tests/other/test_xlocale.c @@ -0,0 +1,10 @@ +#include +#include + +int main() { + const char* input = "100001"; + locale_t l = newlocale(LC_ALL_MASK, "C", NULL); + printf("strtoll_l: %lld\n", strtoll_l(input, NULL, 10, l)); + return 0; +} + diff --git a/tests/other/test_xlocale.out b/tests/other/test_xlocale.out new file mode 100644 index 0000000000000..bdbeb45628a33 --- /dev/null +++ b/tests/other/test_xlocale.out @@ -0,0 +1 @@ +strtoll_l: 100001 diff --git a/tests/test_other.py b/tests/test_other.py index c76f7748ac25f..68928a5789b1e 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -12053,3 +12053,7 @@ def test_lto_atexit(self): # With EXIT_RUNTIME we expect to see the dtor running. self.set_setting('EXIT_RUNTIME') self.do_runf(test_file('other/test_lto_atexit.c'), 'main done\nmy_dtor\n') + + def test_xlocale(self): + # Test for xlocale.h compatibility header + self.do_other_test('test_xlocale.c')