55 * Path to locale storage directory. See ../i18n/_loc_path.h
56 */
57 char *_PathLocale = _DFLT_LOC_PATH;
58
59 static char *current_locale(locale_t, int);
60 static void install_legacy(locale_t, int);
61
62 char *
63 setlocale(int category, const char *locname)
64 {
65 locale_t oldloc;
66 locale_t newloc;
67 int mask;
68
69 if (category < 0 || category > LC_ALL) {
70 errno = EINVAL;
71 return (NULL);
72 }
73
74 if (locname == NULL)
75 return (current_locale(__global_locale, category));
76
77 if ((oldloc = duplocale(__global_locale)) == NULL)
78 return (NULL);
79
80 mask = (category == LC_ALL ? LC_ALL_MASK : (1 << category));
81
82 newloc = newlocale(mask, locname, oldloc);
83 if (newloc == NULL) {
84 freelocale(oldloc);
85 return (NULL);
86 }
87
88 oldloc = __global_locale;
89 __global_locale = newloc;
90
91 install_legacy(newloc, mask);
92
93 freelocale(oldloc);
94 return (current_locale(newloc, category));
95 }
96
97 static char *
98 current_locale(locale_t loc, int cat)
99 {
100 int composite = 0;
101 static char buf[LC_ALL * (ENCODING_LEN + 1 + 1)];
102
103 if (cat != LC_ALL) {
104 return (loc->locdata[cat]->l_lname);
105 }
106
107 /* Look to see if any category is different */
108 for (int i = 1; i < LC_ALL; ++i) {
109 if (strcmp(loc->locdata[0]->l_lname,
|
55 * Path to locale storage directory. See ../i18n/_loc_path.h
56 */
57 char *_PathLocale = _DFLT_LOC_PATH;
58
59 static char *current_locale(locale_t, int);
60 static void install_legacy(locale_t, int);
61
62 char *
63 setlocale(int category, const char *locname)
64 {
65 locale_t oldloc;
66 locale_t newloc;
67 int mask;
68
69 if (category < 0 || category > LC_ALL) {
70 errno = EINVAL;
71 return (NULL);
72 }
73
74 if (locname == NULL)
75 return (current_locale(___global_locale, category));
76
77 if ((oldloc = duplocale(___global_locale)) == NULL)
78 return (NULL);
79
80 mask = (category == LC_ALL ? LC_ALL_MASK : (1 << category));
81
82 newloc = newlocale(mask, locname, oldloc);
83 if (newloc == NULL) {
84 freelocale(oldloc);
85 return (NULL);
86 }
87
88 oldloc = ___global_locale;
89 ___global_locale = newloc;
90
91 install_legacy(newloc, mask);
92
93 freelocale(oldloc);
94 return (current_locale(newloc, category));
95 }
96
97 static char *
98 current_locale(locale_t loc, int cat)
99 {
100 int composite = 0;
101 static char buf[LC_ALL * (ENCODING_LEN + 1 + 1)];
102
103 if (cat != LC_ALL) {
104 return (loc->locdata[cat]->l_lname);
105 }
106
107 /* Look to see if any category is different */
108 for (int i = 1; i < LC_ALL; ++i) {
109 if (strcmp(loc->locdata[0]->l_lname,
|