]> git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/locale/uselocale.c
WASI libc prototype implementation.
[wasi-libc.git] / libc-top-half / musl / src / locale / uselocale.c
1 #include "locale_impl.h"
2 #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
3 #include "pthread_impl.h"
4 #endif
5 #include "libc.h"
6
7 locale_t __uselocale(locale_t new)
8 {
9 #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
10 pthread_t self = __pthread_self();
11 locale_t old = self->locale;
12 #else
13 locale_t old = &libc.global_locale;
14 #endif
15 locale_t global = &libc.global_locale;
16
17 #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
18 if (new) self->locale = new == LC_GLOBAL_LOCALE ? global : new;
19 #else
20 if (new != NULL && new != global && new != LC_GLOBAL_LOCALE) {
21 fputs("non-global locale not supported yet", stderr);
22 __builtin_trap();
23 }
24 #endif
25
26 return old == global ? LC_GLOBAL_LOCALE : old;
27 }
28
29 weak_alias(__uselocale, uselocale);