1 /* setlocale() function that respects the locale chosen by the user.
2 Copyright (C) 2009 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2009.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published
7 by the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24 /* Override setlocale() and newlocale() so that when the default locale is
25 requested (locale = "") and no relevant environment variable is set, the
26 locale chosen by the user is used.
27 This matters on MacOS X 10 and Windows.
28 See the comments in localename.c, function gl_locale_name_default. */
34 /* When building a DLL, we must export some functions. Note that because
35 the functions are only defined for binary backward compatibility, we
36 don't need to use __declspec(dllimport) in any case. */
37 #if HAVE_VISIBILITY && BUILDING_DLL
38 # define DLL_EXPORTED __attribute__((__visibility__("default")))
39 #elif defined _MSC_VER && BUILDING_DLL
40 # define DLL_EXPORTED __declspec(dllexport)
47 #if (defined __APPLE__ && defined __MACH__) || defined _WIN32 || defined __WIN32__ || defined __CYGWIN__
52 /* Return string representation of locale category CATEGORY. */
54 category_to_name (int category)
61 retval = "LC_COLLATE";
67 retval = "LC_MONETARY";
70 retval = "LC_NUMERIC";
76 retval = "LC_MESSAGES";
79 /* If you have a better idea for a default value let me know. */
86 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
88 /* The native Win32 setlocale() function expects locale names of the form
89 "German" or "German_Germany" or "DEU", but not "de" or "de_DE". We need
90 to convert the names from the form with ISO 639 language code and ISO 3166
91 country code to the form with English names or with three-letter identifier.
92 The three-letter identifiers known by a Windows XP SP2 or SP3 are:
93 AFK Afrikaans_South Africa.1252
94 ARA Arabic_Saudi Arabia.1256
95 ARB Arabic_Lebanon.1256
97 ARG Arabic_Algeria.1256
98 ARH Arabic_Bahrain.1256
100 ARJ Arabic_Jordan.1256
101 ARK Arabic_Kuwait.1256
102 ARL Arabic_Libya.1256
103 ARM Arabic_Morocco.1256
105 ARQ Arabic_Qatar.1256
106 ARS Arabic_Syria.1256
107 ART Arabic_Tunisia.1256
108 ARU Arabic_U.A.E..1256
109 ARY Arabic_Yemen.1256
110 AZE Azeri (Latin)_Azerbaijan.1254
111 BEL Belarusian_Belarus.1251
112 BGR Bulgarian_Bulgaria.1251
113 BSB Bosnian_Bosnia and Herzegovina.1250
114 BSC Bosnian (Cyrillic)_Bosnia and Herzegovina.1250 (wrong encoding!)
115 CAT Catalan_Spain.1252
116 CHH Chinese_Hong Kong S.A.R..950
117 CHI Chinese_Singapore.936
118 CHS Chinese_People's Republic of China.936
119 CHT Chinese_Taiwan.950
120 CSY Czech_Czech Republic.1250
121 CYM Welsh_United Kingdom.1252
122 DAN Danish_Denmark.1252
123 DEA German_Austria.1252
124 DEC German_Liechtenstein.1252
125 DEL German_Luxembourg.1252
126 DES German_Switzerland.1252
127 DEU German_Germany.1252
128 ELL Greek_Greece.1253
129 ENA English_Australia.1252
130 ENB English_Caribbean.1252
131 ENC English_Canada.1252
132 ENG English_United Kingdom.1252
133 ENI English_Ireland.1252
134 ENJ English_Jamaica.1252
135 ENL English_Belize.1252
136 ENP English_Republic of the Philippines.1252
137 ENS English_South Africa.1252
138 ENT English_Trinidad and Tobago.1252
139 ENU English_United States.1252
140 ENW English_Zimbabwe.1252
141 ENZ English_New Zealand.1252
142 ESA Spanish_Panama.1252
143 ESB Spanish_Bolivia.1252
144 ESC Spanish_Costa Rica.1252
145 ESD Spanish_Dominican Republic.1252
146 ESE Spanish_El Salvador.1252
147 ESF Spanish_Ecuador.1252
148 ESG Spanish_Guatemala.1252
149 ESH Spanish_Honduras.1252
150 ESI Spanish_Nicaragua.1252
151 ESL Spanish_Chile.1252
152 ESM Spanish_Mexico.1252
153 ESN Spanish_Spain.1252
154 ESO Spanish_Colombia.1252
155 ESP Spanish_Spain.1252
156 ESR Spanish_Peru.1252
157 ESS Spanish_Argentina.1252
158 ESU Spanish_Puerto Rico.1252
159 ESV Spanish_Venezuela.1252
160 ESY Spanish_Uruguay.1252
161 ESZ Spanish_Paraguay.1252
162 ETI Estonian_Estonia.1257
163 EUQ Basque_Spain.1252
165 FIN Finnish_Finland.1252
166 FOS Faroese_Faroe Islands.1252
167 FPO Filipino_Philippines.1252
168 FRA French_France.1252
169 FRB French_Belgium.1252
170 FRC French_Canada.1252
171 FRL French_Luxembourg.1252
172 FRM French_Principality of Monaco.1252
173 FRS French_Switzerland.1252
174 FYN Frisian_Netherlands.1252
175 GLC Galician_Spain.1252
176 HEB Hebrew_Israel.1255
177 HRB Croatian_Bosnia and Herzegovina.1250
178 HRV Croatian_Croatia.1250
179 HUN Hungarian_Hungary.1250
180 IND Indonesian_Indonesia.1252
181 IRE Irish_Ireland.1252
182 ISL Icelandic_Iceland.1252
183 ITA Italian_Italy.1252
184 ITS Italian_Switzerland.1252
185 IUK Inuktitut (Latin)_Canada.1252
186 JPN Japanese_Japan.932
187 KKZ Kazakh_Kazakhstan.1251
189 KYR Kyrgyz_Kyrgyzstan.1251
190 LBX Luxembourgish_Luxembourg.1252
191 LTH Lithuanian_Lithuania.1257
192 LVI Latvian_Latvia.1257
193 MKI FYRO Macedonian_Former Yugoslav Republic of Macedonia.1251
194 MON Mongolian_Mongolia.1251
195 MPD Mapudungun_Chile.1252
196 MSB Malay_Brunei Darussalam.1252
197 MSL Malay_Malaysia.1252
198 MWK Mohawk_Canada.1252
199 NLB Dutch_Belgium.1252
200 NLD Dutch_Netherlands.1252
201 NON Norwegian-Nynorsk_Norway.1252
202 NOR Norwegian (Bokmål)_Norway.1252
203 NSO Northern Sotho_South Africa.1252
204 PLK Polish_Poland.1250
205 PTB Portuguese_Brazil.1252
206 PTG Portuguese_Portugal.1252
207 QUB Quechua_Bolivia.1252
208 QUE Quechua_Ecuador.1252
209 QUP Quechua_Peru.1252
210 RMC Romansh_Switzerland.1252
211 ROM Romanian_Romania.1250
212 RUS Russian_Russia.1251
213 SKY Slovak_Slovakia.1250
214 SLV Slovenian_Slovenia.1250
215 SMA Sami (Southern)_Norway.1252
216 SMB Sami (Southern)_Sweden.1252
217 SME Sami (Northern)_Norway.1252
218 SMF Sami (Northern)_Sweden.1252
219 SMG Sami (Northern)_Finland.1252
220 SMJ Sami (Lule)_Norway.1252
221 SMK Sami (Lule)_Sweden.1252
222 SMN Sami (Inari)_Finland.1252
223 SMS Sami (Skolt)_Finland.1252
224 SQI Albanian_Albania.1250
225 SRB Serbian (Cyrillic)_Serbia and Montenegro.1251
226 SRL Serbian (Latin)_Serbia and Montenegro.1250
227 SRN Serbian (Cyrillic)_Bosnia and Herzegovina.1251
228 SRS Serbian (Latin)_Bosnia and Herzegovina.1250
229 SVE Swedish_Sweden.1252
230 SVF Swedish_Finland.1252
231 SWK Swahili_Kenya.1252
232 THA Thai_Thailand.874
233 TRK Turkish_Turkey.1254
234 TSN Tswana_South Africa.1252
235 TTT Tatar_Russia.1251
236 UKR Ukrainian_Ukraine.1251
237 URD Urdu_Islamic Republic of Pakistan.1256
238 USA English_United States.1252
239 UZB Uzbek (Latin)_Uzbekistan.1254
240 VIT Vietnamese_Viet Nam.1258
241 XHO Xhosa_South Africa.1252
242 ZHH Chinese_Hong Kong S.A.R..950
243 ZHI Chinese_Singapore.936
244 ZHM Chinese_Macau S.A.R..950
245 ZUL Zulu_South Africa.1252
248 /* Table from ISO 639 language code, optionally with country or script suffix,
250 Keep in sync with the gl_locale_name_from_win32_LANGID function in
257 static const struct table_entry language_table[] =
259 { "af", "Afrikaans" },
262 { "arn", "Mapudungun" },
263 { "as", "Assamese" },
264 { "az@cyrillic", "Azeri (Cyrillic)" },
265 { "az@latin", "Azeri (Latin)" },
267 { "be", "Belarusian" },
268 { "ber", "Tamazight" },
269 { "ber@arabic", "Tamazight (Arabic)" },
270 { "ber@latin", "Tamazight (Latin)" },
271 { "bg", "Bulgarian" },
274 { "bn_BD", "Bengali (Bangladesh)" },
275 { "bn_IN", "Bengali (India)" },
279 { "bs", "BSB" }, /* "Bosnian (Latin)" */
280 { "bs@cyrillic", "BSC" }, /* Bosnian (Cyrillic) */
282 { "chr", "Cherokee" },
283 { "co", "Corsican" },
284 { "cpe", "Hawaiian" },
289 { "dsb", "Lower Sorbian" },
294 { "et", "Estonian" },
297 { "ff", "Fulfulde" },
299 { "fo", "Faroese" }, /* "Faeroese" does not work */
302 { "ga", "IRE" }, /* Gaelic (Ireland) */
303 { "gd", "Gaelic (Scotland)" },
304 { "gd", "Scottish Gaelic" },
305 { "gl", "Galician" },
307 { "gsw", "Alsatian" },
308 { "gu", "Gujarati" },
312 { "hr", "Croatian" },
313 { "hsb", "Upper Sorbian" },
314 { "hu", "Hungarian" },
315 { "hy", "Armenian" },
316 { "id", "Indonesian" },
319 { "is", "Icelandic" },
321 { "iu", "IUK" }, /* Inuktitut */
322 { "ja", "Japanese" },
323 { "ka", "Georgian" },
325 { "kl", "Greenlandic" },
326 { "km", "Cambodian" },
330 { "kok", "Konkani" },
332 { "ks", "Kashmiri" },
333 { "ks_IN", "Kashmiri_India" },
334 { "ks_PK", "Kashmiri (Arabic)_Pakistan" },
337 { "lb", "Luxembourgish" },
339 { "lt", "Lithuanian" },
342 { "mk", "FYRO Macedonian" },
343 { "mk", "Macedonian" },
344 { "ml", "Malayalam" },
345 { "mn", "Mongolian" },
346 { "mni", "Manipuri" },
352 { "nb", "NOR" }, /* Norwegian Bokmål */
356 { "nn", "NON" }, /* Norwegian Nynorsk */
357 { "no", "Norwegian" },
358 { "nso", "Northern Sotho" },
364 { "pap", "Papiamentu" },
368 { "pt", "Portuguese" },
370 { "qut", "K'iche'" },
372 { "ro", "Romanian" },
374 { "rw", "Kinyarwanda" },
375 { "sa", "Sanskrit" },
378 { "se", "Sami (Northern)" },
379 { "se", "Northern Sami" },
380 { "si", "Sinhalese" },
382 { "sl", "Slovenian" },
383 { "sma", "Sami (Southern)" },
384 { "sma", "Southern Sami" },
385 { "smj", "Sami (Lule)" },
386 { "smj", "Lule Sami" },
387 { "smn", "Sami (Inari)" },
388 { "smn", "Inari Sami" },
389 { "sms", "Sami (Skolt)" },
390 { "sms", "Skolt Sami" },
392 { "sq", "Albanian" },
393 { "sr", "Serbian (Latin)" },
394 { "sr@cyrillic", "SRB" }, /* Serbian (Cyrillic) */
401 { "ti", "Tigrinya" },
403 { "tl", "Filipino" },
409 { "uk", "Ukrainian" },
412 { "uz", "Uzbek (Latin)" },
413 { "uz@cyrillic", "Uzbek (Cyrillic)" },
415 { "vi", "Vietnamese" },
416 { "wen", "Sorbian" },
425 /* Table from ISO 3166 country code to English name.
426 Keep in sync with the gl_locale_name_from_win32_LANGID function in
428 static const struct table_entry country_table[] =
431 { "AF", "Afghanistan" },
434 { "AN", "Netherlands Antilles" },
435 { "AR", "Argentina" },
437 { "AU", "Australia" },
438 { "AZ", "Azerbaijan" },
439 { "BA", "Bosnia and Herzegovina" },
440 { "BD", "Bangladesh" },
442 { "BG", "Bulgaria" },
444 { "BN", "Brunei Darussalam" },
452 { "CH", "Switzerland" },
453 { "CI", "Cote d'Ivoire" },
455 { "CM", "Cameroon" },
456 { "CN", "People's Republic of China" },
457 { "CO", "Colombia" },
458 { "CR", "Costa Rica" },
459 { "CS", "Serbia and Montenegro" },
460 { "CZ", "Czech Republic" },
463 { "DO", "Dominican Republic" },
470 { "ET", "Ethiopia" },
472 { "FO", "Faroe Islands" },
474 { "GB", "United Kingdom" },
475 { "GD", "Caribbean" },
477 { "GL", "Greenland" },
479 { "GT", "Guatemala" },
480 { "HK", "Hong Kong" },
481 { "HK", "Hong Kong S.A.R." },
482 { "HN", "Honduras" },
486 { "ID", "Indonesia" },
498 { "KG", "Kyrgyzstan" },
499 { "KH", "Cambodia" },
500 { "KR", "South Korea" },
502 { "KZ", "Kazakhstan" },
505 { "LI", "Liechtenstein" },
506 { "LK", "Sri Lanka" },
507 { "LT", "Lithuania" },
508 { "LU", "Luxembourg" },
512 { "MC", "Principality of Monaco" },
515 { "ME", "Montenegro" },
516 { "MK", "Former Yugoslav Republic of Macedonia" },
519 { "MN", "Mongolia" },
520 { "MO", "Macau S.A.R." },
522 { "MV", "Maldives" },
524 { "MY", "Malaysia" },
526 { "NI", "Nicaragua" },
527 { "NL", "Netherlands" },
530 { "NZ", "New Zealand" },
534 { "PH", "Philippines" },
535 { "PK", "Islamic Republic of Pakistan" },
537 { "PR", "Puerto Rico" },
538 { "PT", "Portugal" },
539 { "PY", "Paraguay" },
546 { "SA", "Saudi Arabia" },
548 { "SG", "Singapore" },
549 { "SI", "Slovenia" },
553 { "SR", "Suriname" },
554 { "SV", "El Salvador" },
556 { "TH", "Thailand" },
557 { "TJ", "Tajikistan" },
558 { "TM", "Turkmenistan" },
561 { "TT", "Trinidad and Tobago" },
563 { "TZ", "Tanzania" },
565 { "US", "United States" },
568 { "VE", "Venezuela" },
569 { "VN", "Viet Nam" },
571 { "ZA", "South Africa" },
575 /* Given a string STRING, find the set of indices i such that TABLE[i].code is
576 the given STRING. It is a range [lo,hi-1]. */
577 typedef struct { size_t lo; size_t hi; } range_t;
579 search (const struct table_entry *table, size_t table_size, const char *string,
582 /* The table is sorted. Perform a binary search. */
583 size_t hi = table_size;
588 for i < lo, strcmp (table[i].code, string) < 0,
589 for i >= hi, strcmp (table[i].code, string) > 0. */
590 size_t mid = (hi + lo) >> 1; /* >= lo, < hi */
591 int cmp = strcmp (table[mid].code, string);
599 strcmp (language_table[i].code, string) == 0.
600 Find the entire interval of such i. */
604 for (i = mid; i > lo; )
607 if (strcmp (table[i].code, string) < 0)
617 for (i = mid; i < hi; i++)
619 if (strcmp (table[i].code, string) > 0)
627 strcmp (language_table[i].code, string) == 0
628 is the interval [lo, hi-1]. */
636 /* Like setlocale, but accept also locale names in the form ll or ll_CC,
637 where ll is an ISO 639 language code and CC is an ISO 3166 country code. */
639 setlocale_unixlike (int category, const char *locale)
646 /* First, try setlocale with the original argument unchanged. */
647 result = setlocale (category, locale);
651 /* Otherwise, assume the argument is in the form
652 language[_territory][.codeset][@modifier]
653 and try to map it using the tables. */
654 if (strlen (locale) < sizeof (llCC_buf))
656 /* Second try: Remove the codeset part. */
658 const char *p = locale;
661 /* Copy the part before the dot. */
662 for (; *p != '\0' && *p != '.'; p++, q++)
665 /* Skip the part up to the '@', if any. */
666 for (; *p != '\0' && *p != '@'; p++)
668 /* Copy the part starting with '@', if any. */
669 for (; *p != '\0'; p++, q++)
673 /* llCC_buf now contains
674 language[_territory][@modifier]
676 if (strcmp (llCC_buf, locale) != 0)
678 result = setlocale (category, llCC_buf);
682 /* Look it up in language_table. */
687 search (language_table,
688 sizeof (language_table) / sizeof (language_table[0]),
692 for (i = range.lo; i < range.hi; i++)
694 /* Try the replacement in language_table[i]. */
695 result = setlocale (category, language_table[i].english);
700 /* Split language[_territory][@modifier]
701 into ll_buf = language[@modifier]
702 and CC_buf = territory
705 const char *underscore = strchr (llCC_buf, '_');
706 if (underscore != NULL)
708 const char *territory_start = underscore + 1;
709 const char *territory_end = strchr (territory_start, '@');
710 if (territory_end == NULL)
711 territory_end = territory_start + strlen (territory_start);
713 memcpy (ll_buf, llCC_buf, underscore - llCC_buf);
714 strcpy (ll_buf + (underscore - llCC_buf), territory_end);
716 memcpy (CC_buf, territory_start, territory_end - territory_start);
717 CC_buf[territory_end - territory_start] = '\0';
720 /* Look up ll_buf in language_table
721 and CC_buf in country_table. */
722 range_t language_range;
724 search (language_table,
725 sizeof (language_table) / sizeof (language_table[0]),
728 if (language_range.lo < language_range.hi)
730 range_t country_range;
732 search (country_table,
733 sizeof (country_table) / sizeof (country_table[0]),
736 if (country_range.lo < country_range.hi)
741 for (i = language_range.lo; i < language_range.hi; i++)
742 for (j = country_range.lo; j < country_range.hi; j++)
744 /* Concatenate the replacements. */
745 const char *part1 = language_table[i].english;
746 size_t part1_len = strlen (part1);
747 const char *part2 = country_table[j].english;
748 size_t part2_len = strlen (part2) + 1;
751 if (!(part1_len + 1 + part2_len <= sizeof (buf)))
753 memcpy (buf, part1, part1_len);
754 buf[part1_len] = '_';
755 memcpy (buf + part1_len + 1, part2, part2_len);
757 /* Try the concatenated replacements. */
758 result = setlocale (category, buf);
764 /* Try omitting the country entirely. This may set a locale
765 corresponding to the wrong country, but is better than
770 for (i = language_range.lo; i < language_range.hi; i++)
772 /* Try only the language replacement. */
774 setlocale (category, language_table[i].english);
790 # define setlocale_unixlike setlocale
793 # if LC_MESSAGES == 1729
795 /* The system does not store an LC_MESSAGES locale category. Do it here. */
796 static char lc_messages_name[64] = "C";
798 /* Like setlocale, but support also LC_MESSAGES. */
800 setlocale_single (int category, const char *locale)
802 if (category == LC_MESSAGES)
806 lc_messages_name[sizeof (lc_messages_name) - 1] = '\0';
807 strncpy (lc_messages_name, locale, sizeof (lc_messages_name) - 1);
809 return lc_messages_name;
812 return setlocale_unixlike (category, locale);
816 # define setlocale_single setlocale_unixlike
821 libintl_setlocale (int category, const char *locale)
823 if (locale != NULL && locale[0] == '\0')
825 /* A request to the set the current locale to the default locale. */
826 if (category == LC_ALL)
828 /* Set LC_CTYPE first. Then the other categories. */
829 static int const categories[] =
838 const char *base_name;
841 /* Back up the old locale, in case one of the steps fails. */
842 saved_locale = setlocale (LC_ALL, NULL);
843 if (saved_locale == NULL)
845 saved_locale = strdup (saved_locale);
846 if (saved_locale == NULL)
849 /* Set LC_CTYPE category. Set all other categories (except possibly
850 LC_MESSAGES) to the same value in the same call; this is likely to
853 gl_locale_name_environ (LC_CTYPE, category_to_name (LC_CTYPE));
854 if (base_name == NULL)
855 base_name = gl_locale_name_default ();
857 if (setlocale_unixlike (LC_ALL, base_name) == NULL)
860 for (i = 0; i < sizeof (categories) / sizeof (categories[0]); i++)
862 int cat = categories[i];
865 name = gl_locale_name_environ (cat, category_to_name (cat));
867 name = gl_locale_name_default ();
869 /* If name is the same as base_name, it has already been set
870 through the setlocale call before the loop. */
871 if (strcmp (name, base_name) != 0
872 # if LC_MESSAGES == 1729
873 || cat == LC_MESSAGES
876 if (setlocale_single (cat, name) == NULL)
880 /* All steps were successful. */
882 return setlocale (LC_ALL, NULL);
885 if (saved_locale[0] != '\0') /* don't risk an endless recursion */
886 setlocale (LC_ALL, saved_locale);
893 gl_locale_name_environ (category, category_to_name (category));
895 name = gl_locale_name_default ();
897 return setlocale_single (category, name);
901 return setlocale_single (category, locale);
908 libintl_newlocale (int category_mask, const char *locale, locale_t base)
910 if (category_mask != 0 && locale != NULL && locale[0] == '\0')
912 /* A request to construct a locale_t object that refers to the default
915 /* Set LC_CTYPE first. Then the other categories. */
916 static struct { int cat; int mask; } const categories[] =
918 { LC_CTYPE, LC_CTYPE_MASK },
919 { LC_NUMERIC, LC_NUMERIC_MASK },
920 { LC_TIME, LC_TIME_MASK },
921 { LC_COLLATE, LC_COLLATE_MASK },
922 { LC_MONETARY, LC_MONETARY_MASK },
923 { LC_MESSAGES, LC_MESSAGES_MASK }
926 locale_t orig_base = base;
928 if ((LC_ALL_MASK & ~category_mask) == 0)
930 const char *base_name;
933 /* Set LC_CTYPE category. Set all other categories (except possibly
934 LC_MESSAGES) to the same value in the same call; this is likely to
937 gl_locale_name_environ (LC_CTYPE, category_to_name (LC_CTYPE));
938 if (base_name == NULL)
939 base_name = gl_locale_name_default ();
941 base = newlocale (LC_ALL_MASK, base_name, base);
945 for (i = 1; i < sizeof (categories) / sizeof (categories[0]); i++)
947 int category = categories[i].cat;
948 int category_mask = categories[i].mask;
952 gl_locale_name_environ (category, category_to_name (category));
954 name = gl_locale_name_default ();
956 /* If name is the same as base_name, it has already been set
957 through the setlocale call before the loop. */
958 if (strcmp (name, base_name) != 0)
960 locale_t copy = newlocale (category_mask, name, base);
963 /* No need to call freelocale (base) if copy != base; the
964 newlocale function already takes care of doing it. */
973 for (i = 0; i < sizeof (categories) / sizeof (categories[0]); i++)
975 int cat_mask = categories[i].mask;
977 if ((category_mask & cat_mask) != 0)
979 int cat = categories[i].cat;
983 name = gl_locale_name_environ (cat, category_to_name (cat));
985 name = gl_locale_name_default ();
987 copy = newlocale (cat_mask, name, base);
990 /* No need to call freelocale (base) if copy != base; the
991 newlocale function already takes care of doing it. */
997 /* All steps were successful. */
1001 if (base != NULL && orig_base == NULL)
1003 int saved_errno = errno;
1005 errno = saved_errno;
1010 return newlocale (category_mask, locale, base);