4 #include "locale_impl.h"
8 static char buf[2+4*(LOCALE_NAME_MAX+1)];
10 char *setlocale(int cat, const char *name)
12 if (!libc.global_locale.messages_name) {
13 libc.global_locale.messages_name =
14 buf + 2 + 3*(LOCALE_NAME_MAX+1);
17 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. */
26 char part[LOCALE_NAME_MAX+1];
28 if (name[0] && name[1]==';'
29 && strlen(name) > 2 + 3*(LOCALE_NAME_MAX+1)) {
32 setlocale(LC_CTYPE, part);
33 part[LOCALE_NAME_MAX] = 0;
34 for (i=LC_TIME; i<LC_MESSAGES; i++) {
35 memcpy(part, name + 2 + (i-2)*(LOCALE_NAME_MAX+1), LOCALE_NAME_MAX);
36 for (j=LOCALE_NAME_MAX-1; j && part[j]==';'; j--)
40 setlocale(LC_MESSAGES, name + 2 + 3*(LOCALE_NAME_MAX+1));
42 for (i=0; i<LC_ALL; i++)
46 memset(buf, ';', 2 + 3*(LOCALE_NAME_MAX+1));
47 buf[0] = libc.global_locale.ctype_utf8 ? 'U' : 'C';
52 int adj = libc.global_locale.ctype_utf8;
53 __setlocalecat(&libc.global_locale, cat, name);
54 adj -= libc.global_locale.ctype_utf8;
55 if (adj) a_fetch_add(&libc.bytelocale_cnt_minus_1, adj);
60 return libc.global_locale.ctype_utf8 ? "C.UTF-8" : "C";
62 return libc.global_locale.messages_name[0]
63 ? libc.global_locale.messages_name : "C";