4 #include "locale_impl.h"
8 static char buf[LC_ALL*(LOCALE_NAME_MAX+1)];
10 char *setlocale(int cat, const char *name)
12 static volatile int lock[1];
13 const struct __locale_map *lm;
15 if ((unsigned)cat > LC_ALL) return 0;
19 /* For LC_ALL, setlocale is required to return a string which
20 * encodes the current setting for all categories. The format of
21 * this string is unspecified, and only the following code, which
22 * performs both the serialization and deserialization, depends
23 * on the format, so it can easily be changed if needed. */
27 struct __locale_struct tmp_locale;
28 char part[LOCALE_NAME_MAX+1] = "C.UTF-8";
30 for (i=0; i<LC_ALL; i++) {
31 const char *z = __strchrnul(p, ';');
32 if (z-p <= LOCALE_NAME_MAX) {
37 lm = __get_locale(i, name);
38 if (lm == LOC_MAP_FAILED) {
42 tmp_locale.cat[i] = lm;
44 libc.global_locale = tmp_locale;
49 for (i=0; i<LC_ALL; i++) {
50 const struct __locale_map *lm =
51 libc.global_locale.cat[i];
52 if (lm == libc.global_locale.cat[0]) same++;
53 part = lm ? lm->name : "C";
54 size_t l = strlen(part);
61 return same==LC_ALL ? (char *)part : buf;
65 lm = __get_locale(cat, name);
66 if (lm == LOC_MAP_FAILED) {
70 libc.global_locale.cat[cat] = lm;
72 lm = libc.global_locale.cat[cat];
74 char *ret = lm ? (char *)lm->name : "C";