Skip to content

Commit 60a1dc1

Browse files
authored
Restore xlocale.h compat header. (#17111)
This is a parial revert or #17022 ("Define _LIBCPP_HAS_MUSL_LIBC in libcxx build") Also, add a new test for this header.
1 parent 1cfde30 commit 60a1dc1

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

system/include/compat/xlocale.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef _COMPAT_XLOCALE_H_
2+
#define _COMPAT_XLOCALE_H_
3+
4+
#include <locale.h>
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
long long strtoll_l(const char *start, char **end, int base, locale_t loc);
11+
unsigned long long strtoull_l(const char *start, char **end, int base, locale_t loc);
12+
long double strtold_l(const char *start, char **end, locale_t loc);
13+
14+
#ifdef __cplusplus
15+
}
16+
#endif
17+
18+
#endif /* _COMPAT_XLOCALE_H_ */

system/lib/libc/compat/strtol_l.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <stdlib.h>
2+
#include <ctype.h>
3+
4+
unsigned long long strtoull_l(const char *restrict s, char **restrict p, int base, locale_t loc)
5+
{
6+
return strtoull(s, p, base);
7+
}
8+
9+
long long strtoll_l(const char *restrict s, char **restrict p, int base, locale_t loc)
10+
{
11+
return strtoll(s, p, base);
12+
}
13+
14+
unsigned long strtoul_l(const char *restrict s, char **restrict p, int base, locale_t loc)
15+
{
16+
return strtoul(s, p, base);
17+
}
18+
19+
long strtol_l(const char *restrict s, char **restrict p, int base, locale_t loc)
20+
{
21+
return strtol(s, p, base);
22+
}

tests/other/test_xlocale.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <xlocale.h>
2+
#include <stdio.h>
3+
4+
int main() {
5+
const char* input = "100001";
6+
locale_t l = newlocale(LC_ALL_MASK, "C", NULL);
7+
printf("strtoll_l: %lld\n", strtoll_l(input, NULL, 10, l));
8+
return 0;
9+
}
10+

tests/other/test_xlocale.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
strtoll_l: 100001

tests/test_other.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12063,3 +12063,7 @@ def test_lto_atexit(self):
1206312063
# With EXIT_RUNTIME we expect to see the dtor running.
1206412064
self.set_setting('EXIT_RUNTIME')
1206512065
self.do_runf(test_file('other/test_lto_atexit.c'), 'main done\nmy_dtor\n')
12066+
12067+
def test_xlocale(self):
12068+
# Test for xlocale.h compatibility header
12069+
self.do_other_test('test_xlocale.c')

0 commit comments

Comments
 (0)