Skip to content

Restore xlocale.h compat header. #17111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions system/include/compat/xlocale.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _COMPAT_XLOCALE_H_
#define _COMPAT_XLOCALE_H_

#include <locale.h>

#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_ */
22 changes: 22 additions & 0 deletions system/lib/libc/compat/strtol_l.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdlib.h>
#include <ctype.h>

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);
}
10 changes: 10 additions & 0 deletions tests/other/test_xlocale.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <xlocale.h>
#include <stdio.h>

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;
}

1 change: 1 addition & 0 deletions tests/other/test_xlocale.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
strtoll_l: 100001
4 changes: 4 additions & 0 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')