Debian Codegraph @

libc-top-half/musl/src/locale/uselocale.c

raw
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.current_locale;
14 if (!old) old = LC_GLOBAL_LOCALE;
15 #endif
16 locale_t global = &libc.global_locale;
17
18 #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
19 if (new) self->locale = new == LC_GLOBAL_LOCALE ? global : new;
20 #else
21 if (new) libc.current_locale = new == LC_GLOBAL_LOCALE ? global : new;
22 #endif
23
24 return old == global ? LC_GLOBAL_LOCALE : old;
25 }
26
27 weak_alias(__uselocale, uselocale);