4 #include "locale_impl.h"
8 static char buf
[LC_ALL
*(LOCALE_NAME_MAX
+1)];
10 static char *setlocale_one_unlocked(int cat
, const char *name
)
12 const struct __locale_map
*lm
;
14 if (name
) libc
.global_locale
.cat
[cat
] = lm
= __get_locale(cat
, name
);
15 else lm
= libc
.global_locale
.cat
[cat
];
17 return lm
? (char *)lm
->name
: "C";
20 char *__strchrnul(const char *, int);
22 char *setlocale(int cat
, const char *name
)
24 static volatile int lock
[2];
26 if ((unsigned)cat
> LC_ALL
) return 0;
30 /* For LC_ALL, setlocale is required to return a string which
31 * encodes the current setting for all categories. The format of
32 * this string is unspecified, and only the following code, which
33 * performs both the serialization and deserialization, depends
34 * on the format, so it can easily be changed if needed. */
38 char part
[LOCALE_NAME_MAX
+1] = "C.UTF-8";
40 for (i
=0; i
<LC_ALL
; i
++) {
41 const char *z
= __strchrnul(p
, ';');
42 if (z
-p
<= LOCALE_NAME_MAX
) {
47 setlocale_one_unlocked(i
, part
);
51 for (i
=0; i
<LC_ALL
; i
++) {
52 const struct __locale_map
*lm
=
53 libc
.global_locale
.cat
[i
];
54 const char *part
= lm
? lm
->name
: "C";
55 size_t l
= strlen(part
);
65 char *ret
= setlocale_one_unlocked(cat
, name
);