4 #include "locale_impl.h"
8 static char buf[LC_ALL*(LOCALE_NAME_MAX+1)];
10 char *setlocale(int cat, const char *name)
12 const struct __locale_map *lm;
14 if ((unsigned)cat > LC_ALL) return 0;
18 /* For LC_ALL, setlocale is required to return a string which
19 * encodes the current setting for all categories. The format of
20 * this string is unspecified, and only the following code, which
21 * performs both the serialization and deserialization, depends
22 * on the format, so it can easily be changed if needed. */
26 struct __locale_struct tmp_locale;
27 char part[LOCALE_NAME_MAX+1] = "C.UTF-8";
29 for (i=0; i<LC_ALL; i++) {
30 const char *z = __strchrnul(p, ';');
31 if (z-p <= LOCALE_NAME_MAX) {
36 lm = __get_locale(i, part);
37 if (lm == LOC_MAP_FAILED) {
38 UNLOCK(__locale_lock);
41 tmp_locale.cat[i] = lm;
43 libc.global_locale = tmp_locale;
48 for (i=0; i<LC_ALL; i++) {
49 const struct __locale_map *lm =
50 libc.global_locale.cat[i];
51 if (lm == libc.global_locale.cat[0]) same++;
52 part = lm ? lm->name : "C";
53 size_t l = strlen(part);
59 UNLOCK(__locale_lock);
60 return same==LC_ALL ? (char *)part : buf;
64 lm = __get_locale(cat, name);
65 if (lm == LOC_MAP_FAILED) {
66 UNLOCK(__locale_lock);
69 libc.global_locale.cat[cat] = lm;
71 lm = libc.global_locale.cat[cat];
73 char *ret = lm ? (char *)lm->name : "C";
75 UNLOCK(__locale_lock);