kernel32: Update Italian translation.
[wine/testsucceed.git] / dlls / msvcrt / locale.c
blob5a27de02d017f7b48136cc5e4cc562a8263a8812
1 /*
2 * msvcrt.dll locale functions
4 * Copyright 2000 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <limits.h>
25 #include <locale.h>
26 #include <stdarg.h>
27 #include <stdio.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "winnls.h"
34 #include "msvcrt.h"
35 #include "mtdll.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
41 #define MAX_ELEM_LEN 64 /* Max length of country/language/CP string */
42 #define MAX_LOCALE_LENGTH 256
43 MSVCRT__locale_t MSVCRT_locale = NULL;
44 int MSVCRT___lc_codepage = 0;
45 int MSVCRT___lc_collate_cp = 0;
46 HANDLE MSVCRT___lc_handle[MSVCRT_LC_MAX - MSVCRT_LC_MIN + 1] = { 0 };
47 unsigned char charmax = CHAR_MAX;
49 /* MT */
50 #define LOCK_LOCALE _mlock(_SETLOCALE_LOCK);
51 #define UNLOCK_LOCALE _munlock(_SETLOCALE_LOCK);
53 #define MSVCRT_LEADBYTE 0x8000
54 #define MSVCRT_C1_DEFINED 0x200
56 /* Friendly country strings & language names abbreviations. */
57 static const char * const _country_synonyms[] =
59 "american", "enu",
60 "american english", "enu",
61 "american-english", "enu",
62 "english-american", "enu",
63 "english-us", "enu",
64 "english-usa", "enu",
65 "us", "enu",
66 "usa", "enu",
67 "australian", "ena",
68 "english-aus", "ena",
69 "belgian", "nlb",
70 "french-belgian", "frb",
71 "canadian", "enc",
72 "english-can", "enc",
73 "french-canadian", "frc",
74 "chinese", "chs",
75 "chinese-simplified", "chs",
76 "chinese-traditional", "cht",
77 "dutch-belgian", "nlb",
78 "english-nz", "enz",
79 "uk", "eng",
80 "english-uk", "eng",
81 "french-swiss", "frs",
82 "swiss", "des",
83 "german-swiss", "des",
84 "italian-swiss", "its",
85 "german-austrian", "dea",
86 "portugese", "ptb",
87 "portuguese-brazil", "ptb",
88 "spanish-mexican", "esm",
89 "norwegian-bokmal", "nor",
90 "norwegian-nynorsk", "non",
91 "spanish-modern", "esn"
94 /* INTERNAL: Map a synonym to an ISO code */
95 static void remap_synonym(char *name)
97 unsigned int i;
98 for (i = 0; i < sizeof(_country_synonyms)/sizeof(char*); i += 2 )
100 if (!strcasecmp(_country_synonyms[i],name))
102 TRACE(":Mapping synonym %s to %s\n",name,_country_synonyms[i+1]);
103 memcpy(name, _country_synonyms[i+1], sizeof(_country_synonyms[i+1]));
104 return;
109 /* Note: Flags are weighted in order of matching importance */
110 #define FOUND_LANGUAGE 0x4
111 #define FOUND_COUNTRY 0x2
112 #define FOUND_CODEPAGE 0x1
114 typedef struct {
115 char search_language[MAX_ELEM_LEN];
116 char search_country[MAX_ELEM_LEN];
117 char search_codepage[MAX_ELEM_LEN];
118 char found_codepage[MAX_ELEM_LEN];
119 unsigned int match_flags;
120 LANGID found_lang_id;
121 } locale_search_t;
123 #define CONTINUE_LOOKING TRUE
124 #define STOP_LOOKING FALSE
126 /* INTERNAL: Get and compare locale info with a given string */
127 static int compare_info(LCID lcid, DWORD flags, char* buff, const char* cmp, BOOL exact)
129 int len;
131 buff[0] = 0;
132 GetLocaleInfoA(lcid, flags|LOCALE_NOUSEROVERRIDE, buff, MAX_ELEM_LEN);
133 if (!buff[0] || !cmp[0])
134 return 0;
136 /* Partial matches are only allowed on language/country names */
137 len = strlen(cmp);
138 if(exact || len<=3)
139 return !strcasecmp(cmp, buff);
140 else
141 return !strncasecmp(cmp, buff, len);
144 static BOOL CALLBACK
145 find_best_locale_proc(HMODULE hModule, LPCSTR type, LPCSTR name, WORD LangID, LONG_PTR lParam)
147 locale_search_t *res = (locale_search_t *)lParam;
148 const LCID lcid = MAKELCID(LangID, SORT_DEFAULT);
149 char buff[MAX_ELEM_LEN];
150 unsigned int flags = 0;
152 if(PRIMARYLANGID(LangID) == LANG_NEUTRAL)
153 return CONTINUE_LOOKING;
155 /* Check Language */
156 if (compare_info(lcid,LOCALE_SISO639LANGNAME,buff,res->search_language, TRUE) ||
157 compare_info(lcid,LOCALE_SABBREVLANGNAME,buff,res->search_language, TRUE) ||
158 compare_info(lcid,LOCALE_SENGLANGUAGE,buff,res->search_language, FALSE))
160 TRACE(":Found language: %s->%s\n", res->search_language, buff);
161 flags |= FOUND_LANGUAGE;
163 else if (res->match_flags & FOUND_LANGUAGE)
165 return CONTINUE_LOOKING;
168 /* Check Country */
169 if (compare_info(lcid,LOCALE_SISO3166CTRYNAME,buff,res->search_country, TRUE) ||
170 compare_info(lcid,LOCALE_SABBREVCTRYNAME,buff,res->search_country, TRUE) ||
171 compare_info(lcid,LOCALE_SENGCOUNTRY,buff,res->search_country, FALSE))
173 TRACE("Found country:%s->%s\n", res->search_country, buff);
174 flags |= FOUND_COUNTRY;
176 else if (res->match_flags & FOUND_COUNTRY)
178 return CONTINUE_LOOKING;
181 /* Check codepage */
182 if (compare_info(lcid,LOCALE_IDEFAULTCODEPAGE,buff,res->search_codepage, TRUE) ||
183 (compare_info(lcid,LOCALE_IDEFAULTANSICODEPAGE,buff,res->search_codepage, TRUE)))
185 TRACE("Found codepage:%s->%s\n", res->search_codepage, buff);
186 flags |= FOUND_CODEPAGE;
187 memcpy(res->found_codepage,res->search_codepage,MAX_ELEM_LEN);
189 else if (res->match_flags & FOUND_CODEPAGE)
191 return CONTINUE_LOOKING;
194 if (flags > res->match_flags)
196 /* Found a better match than previously */
197 res->match_flags = flags;
198 res->found_lang_id = LangID;
200 if ((flags & (FOUND_LANGUAGE | FOUND_COUNTRY | FOUND_CODEPAGE)) ==
201 (FOUND_LANGUAGE | FOUND_COUNTRY | FOUND_CODEPAGE))
203 TRACE(":found exact locale match\n");
204 return STOP_LOOKING;
206 return CONTINUE_LOOKING;
209 extern int atoi(const char *);
211 /* Internal: Find the LCID for a locale specification */
212 static LCID MSVCRT_locale_to_LCID(const char *locale)
214 LCID lcid;
215 locale_search_t search;
216 char *cp, *region;
218 memset(&search, 0, sizeof(locale_search_t));
220 cp = strchr(locale, '.');
221 region = strchr(locale, '_');
223 lstrcpynA(search.search_language, locale, MAX_ELEM_LEN);
224 if(region) {
225 lstrcpynA(search.search_country, region+1, MAX_ELEM_LEN);
226 if(region-locale < MAX_ELEM_LEN)
227 search.search_language[region-locale] = '\0';
228 } else
229 search.search_country[0] = '\0';
231 if(cp) {
232 lstrcpynA(search.search_codepage, cp+1, MAX_ELEM_LEN);
233 if(cp-region-1 < MAX_ELEM_LEN)
234 search.search_country[cp-region-1] = '\0';
235 if(cp-locale < MAX_ELEM_LEN)
236 search.search_language[cp-locale] = '\0';
237 } else
238 search.search_codepage[0] = '\0';
240 if(!search.search_country[0] && !search.search_codepage[0])
241 remap_synonym(search.search_language);
243 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), (LPSTR)RT_STRING,
244 (LPCSTR)LOCALE_ILANGUAGE,find_best_locale_proc,
245 (LONG_PTR)&search);
247 if (!search.match_flags)
248 return -1;
250 /* If we were given something that didn't match, fail */
251 if (search.search_country[0] && !(search.match_flags & FOUND_COUNTRY))
252 return -1;
254 lcid = MAKELCID(search.found_lang_id, SORT_DEFAULT);
256 /* Populate partial locale, translating LCID to locale string elements */
257 if (!search.found_codepage[0]) {
258 /* Even if a codepage is not enumerated for a locale
259 * it can be set if valid */
260 if (search.search_codepage[0]) {
261 if (IsValidCodePage(atoi(search.search_codepage)))
262 memcpy(search.found_codepage,search.search_codepage,MAX_ELEM_LEN);
263 else {
264 /* Special codepage values: OEM & ANSI */
265 if (strcasecmp(search.search_codepage,"OCP")) {
266 GetLocaleInfoA(lcid, LOCALE_IDEFAULTCODEPAGE,
267 search.found_codepage, MAX_ELEM_LEN);
268 } else if (strcasecmp(search.search_codepage,"ACP")) {
269 GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE,
270 search.found_codepage, MAX_ELEM_LEN);
271 } else
272 return -1;
274 if (!atoi(search.found_codepage))
275 return -1;
277 } else {
278 /* Prefer ANSI codepages if present */
279 GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE,
280 search.found_codepage, MAX_ELEM_LEN);
281 if (!search.found_codepage[0] || !atoi(search.found_codepage))
282 GetLocaleInfoA(lcid, LOCALE_IDEFAULTCODEPAGE,
283 search.found_codepage, MAX_ELEM_LEN);
287 return lcid;
290 /* INTERNAL: Set lc_handle, lc_id and lc_category in threadlocinfo struct */
291 static BOOL update_threadlocinfo_category(LCID lcid, MSVCRT__locale_t loc, int category)
293 char buf[256], *p;
294 int len;
296 if(GetLocaleInfoA(lcid, LOCALE_ILANGUAGE|LOCALE_NOUSEROVERRIDE, buf, 256)) {
297 p = buf;
299 loc->locinfo->lc_id[category].wLanguage = 0;
300 while(*p) {
301 loc->locinfo->lc_id[category].wLanguage *= 16;
303 if(*p <= '9')
304 loc->locinfo->lc_id[category].wLanguage += *p-'0';
305 else
306 loc->locinfo->lc_id[category].wLanguage += *p-'a'+10;
308 p++;
311 loc->locinfo->lc_id[category].wCountry =
312 loc->locinfo->lc_id[category].wLanguage;
315 if(GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE
316 |LOCALE_NOUSEROVERRIDE, buf, 256))
317 loc->locinfo->lc_id[category].wCodePage = atoi(buf);
319 loc->locinfo->lc_handle[category] = lcid;
321 len = 0;
322 len += GetLocaleInfoA(lcid, LOCALE_SENGLANGUAGE
323 |LOCALE_NOUSEROVERRIDE, buf, 256);
324 buf[len-1] = '_';
325 len += GetLocaleInfoA(lcid, LOCALE_SENGCOUNTRY
326 |LOCALE_NOUSEROVERRIDE, &buf[len], 256-len);
327 buf[len-1] = '.';
328 len += GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE
329 |LOCALE_NOUSEROVERRIDE, &buf[len], 256-len);
331 loc->locinfo->lc_category[category].locale = MSVCRT_malloc(sizeof(char[len]));
332 loc->locinfo->lc_category[category].refcount = MSVCRT_malloc(sizeof(int));
333 if(!loc->locinfo->lc_category[category].locale
334 || !loc->locinfo->lc_category[category].refcount) {
335 MSVCRT_free(loc->locinfo->lc_category[category].locale);
336 MSVCRT_free(loc->locinfo->lc_category[category].refcount);
337 loc->locinfo->lc_category[category].locale = NULL;
338 loc->locinfo->lc_category[category].refcount = NULL;
339 return TRUE;
341 memcpy(loc->locinfo->lc_category[category].locale, buf, sizeof(char[len]));
342 *loc->locinfo->lc_category[category].refcount = 1;
344 return FALSE;
347 /* INTERNAL: swap pointers values */
348 static inline void swap_pointers(void **p1, void **p2) {
349 void *hlp;
351 hlp = *p1;
352 *p1 = *p2;
353 *p2 = hlp;
356 /* INTERNAL: returns _locale_t struct for current locale */
357 MSVCRT__locale_t get_locale(void) {
358 thread_data_t *data = msvcrt_get_thread_data();
360 if(!data || !data->locale)
361 return MSVCRT_locale;
363 return data->locale;
366 /* INTERNAL: constructs string returned by setlocale */
367 static inline char* construct_lc_all(MSVCRT__locale_t cur) {
368 static char current_lc_all[MAX_LOCALE_LENGTH];
370 int i;
372 for(i=MSVCRT_LC_MIN+1; i<MSVCRT_LC_MAX; i++) {
373 if(strcmp(cur->locinfo->lc_category[i].locale,
374 cur->locinfo->lc_category[i+1].locale))
375 break;
378 if(i==MSVCRT_LC_MAX)
379 return cur->locinfo->lc_category[MSVCRT_LC_COLLATE].locale;
381 sprintf(current_lc_all,
382 "LC_COLLATE=%s;LC_CTYPE=%s;LC_MONETARY=%s;LC_NUMERIC=%s;LC_TIME=%s",
383 cur->locinfo->lc_category[MSVCRT_LC_COLLATE].locale,
384 cur->locinfo->lc_category[MSVCRT_LC_CTYPE].locale,
385 cur->locinfo->lc_category[MSVCRT_LC_MONETARY].locale,
386 cur->locinfo->lc_category[MSVCRT_LC_NUMERIC].locale,
387 cur->locinfo->lc_category[MSVCRT_LC_TIME].locale);
389 return current_lc_all;
393 /*********************************************************************
394 * wsetlocale (MSVCRT.@)
396 MSVCRT_wchar_t* CDECL MSVCRT__wsetlocale(int category, const MSVCRT_wchar_t* locale)
398 static MSVCRT_wchar_t fake[] = {
399 'E','n','g','l','i','s','h','_','U','n','i','t','e','d',' ',
400 'S','t','a','t','e','s','.','1','2','5','2',0 };
402 FIXME("%d %s\n", category, debugstr_w(locale));
404 return fake;
407 /*********************************************************************
408 * _Getdays (MSVCRT.@)
410 const char* CDECL _Getdays(void)
412 static const char MSVCRT_days[] = ":Sun:Sunday:Mon:Monday:Tue:Tuesday:Wed:"
413 "Wednesday:Thu:Thursday:Fri:Friday:Sat:Saturday";
414 /* FIXME: Use locale */
415 TRACE("(void) semi-stub\n");
416 return MSVCRT_days;
419 /*********************************************************************
420 * _Getmonths (MSVCRT.@)
422 const char* CDECL _Getmonths(void)
424 static const char MSVCRT_months[] = ":Jan:January:Feb:February:Mar:March:Apr:"
425 "April:May:May:Jun:June:Jul:July:Aug:August:Sep:September:Oct:"
426 "October:Nov:November:Dec:December";
427 /* FIXME: Use locale */
428 TRACE("(void) semi-stub\n");
429 return MSVCRT_months;
432 /*********************************************************************
433 * _Gettnames (MSVCRT.@)
435 const char* CDECL _Gettnames(void)
437 /* FIXME: */
438 TRACE("(void) stub\n");
439 return "";
442 /*********************************************************************
443 * _Strftime (MSVCRT.@)
445 const char* CDECL _Strftime(char *out, unsigned int len, const char *fmt,
446 const void *tm, void *foo)
448 /* FIXME: */
449 TRACE("(%p %d %s %p %p) stub\n", out, len, fmt, tm, foo);
450 return "";
453 /*********************************************************************
454 * __crtLCMapStringA (MSVCRT.@)
456 int CDECL __crtLCMapStringA(
457 LCID lcid, DWORD mapflags, const char* src, int srclen, char* dst,
458 int dstlen, unsigned int codepage, int xflag
460 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
461 lcid,mapflags,src,srclen,dst,dstlen,codepage,xflag);
462 /* FIXME: A bit incorrect. But msvcrt itself just converts its
463 * arguments to wide strings and then calls LCMapStringW
465 return LCMapStringA(lcid,mapflags,src,srclen,dst,dstlen);
468 /*********************************************************************
469 * __crtCompareStringA (MSVCRT.@)
471 int CDECL __crtCompareStringA( LCID lcid, DWORD flags, const char *src1, int len1,
472 const char *src2, int len2 )
474 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
475 lcid, flags, debugstr_a(src1), len1, debugstr_a(src2), len2 );
476 /* FIXME: probably not entirely right */
477 return CompareStringA( lcid, flags, src1, len1, src2, len2 );
480 /*********************************************************************
481 * __crtCompareStringW (MSVCRT.@)
483 int CDECL __crtCompareStringW( LCID lcid, DWORD flags, const MSVCRT_wchar_t *src1, int len1,
484 const MSVCRT_wchar_t *src2, int len2 )
486 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
487 lcid, flags, debugstr_w(src1), len1, debugstr_w(src2), len2 );
488 /* FIXME: probably not entirely right */
489 return CompareStringW( lcid, flags, src1, len1, src2, len2 );
492 /*********************************************************************
493 * __crtGetLocaleInfoW (MSVCRT.@)
495 int CDECL __crtGetLocaleInfoW( LCID lcid, LCTYPE type, MSVCRT_wchar_t *buffer, int len )
497 FIXME("(lcid %x, type %x, %p(%d), partial stub\n", lcid, type, buffer, len );
498 /* FIXME: probably not entirely right */
499 return GetLocaleInfoW( lcid, type, buffer, len );
502 /*********************************************************************
503 * btowc(MSVCRT.@)
505 MSVCRT_wint_t CDECL MSVCRT_btowc(int c)
507 MSVCRT__locale_t locale = get_locale();
508 unsigned char letter = c;
509 MSVCRT_wchar_t ret;
511 if(!MultiByteToWideChar(locale->locinfo->lc_handle[MSVCRT_LC_CTYPE],
512 0, (LPCSTR)&letter, 1, &ret, 1))
513 return 0;
515 return ret;
518 /*********************************************************************
519 * __crtGetStringTypeW(MSVCRT.@)
521 * This function was accepting different number of arguments in older
522 * versions of msvcrt.
524 BOOL CDECL __crtGetStringTypeW(DWORD unk, DWORD type,
525 MSVCRT_wchar_t *buffer, int len, WORD *out)
527 FIXME("(unk %x, type %x, wstr %p(%d), %p) partial stub\n",
528 unk, type, buffer, len, out);
530 return GetStringTypeW(type, buffer, len, out);
533 /*********************************************************************
534 * localeconv (MSVCRT.@)
536 struct MSVCRT_lconv * CDECL MSVCRT_localeconv(void)
538 return get_locale()->locinfo->lconv;
541 /*********************************************************************
542 * __lconv_init (MSVCRT.@)
544 int CDECL __lconv_init(void)
546 /* this is used to make chars unsigned */
547 charmax = 255;
548 return 0;
551 /*********************************************************************
552 * ___lc_handle_func (MSVCRT.@)
554 HANDLE * CDECL ___lc_handle_func(void)
556 return MSVCRT___lc_handle;
559 /*********************************************************************
560 * ___lc_codepage_func (MSVCRT.@)
562 int CDECL ___lc_codepage_func(void)
564 return MSVCRT___lc_codepage;
567 /*********************************************************************
568 * ___lc_collate_cp_func (MSVCRT.@)
570 int CDECL ___lc_collate_cp_func(void)
572 return get_locale()->locinfo->lc_collate_cp;
575 /* _free_locale - not exported in native msvcrt */
576 void CDECL MSVCRT__free_locale(MSVCRT__locale_t locale)
578 int i;
580 if (!locale)
581 return;
583 for(i=MSVCRT_LC_MIN+1; i<=MSVCRT_LC_MAX; i++) {
584 MSVCRT_free(locale->locinfo->lc_category[i].locale);
585 MSVCRT_free(locale->locinfo->lc_category[i].refcount);
588 if(locale->locinfo->lconv) {
589 MSVCRT_free(locale->locinfo->lconv->decimal_point);
590 MSVCRT_free(locale->locinfo->lconv->thousands_sep);
591 MSVCRT_free(locale->locinfo->lconv->grouping);
592 MSVCRT_free(locale->locinfo->lconv->int_curr_symbol);
593 MSVCRT_free(locale->locinfo->lconv->currency_symbol);
594 MSVCRT_free(locale->locinfo->lconv->mon_decimal_point);
595 MSVCRT_free(locale->locinfo->lconv->mon_thousands_sep);
596 MSVCRT_free(locale->locinfo->lconv->mon_grouping);
597 MSVCRT_free(locale->locinfo->lconv->positive_sign);
598 MSVCRT_free(locale->locinfo->lconv->negative_sign);
600 MSVCRT_free(locale->locinfo->lconv_intl_refcount);
601 MSVCRT_free(locale->locinfo->lconv_num_refcount);
602 MSVCRT_free(locale->locinfo->lconv_mon_refcount);
603 MSVCRT_free(locale->locinfo->lconv);
605 MSVCRT_free(locale->locinfo->ctype1_refcount);
606 MSVCRT_free(locale->locinfo->ctype1);
608 MSVCRT_free(locale->locinfo->pclmap);
609 MSVCRT_free(locale->locinfo->pcumap);
611 MSVCRT_free(locale->locinfo);
612 MSVCRT_free(locale->mbcinfo);
613 MSVCRT_free(locale);
616 /* _create_locale - not exported in native msvcrt */
617 MSVCRT__locale_t MSVCRT__create_locale(int category, const char *locale)
619 static const char collate[] = "COLLATE=";
620 static const char ctype[] = "CTYPE=";
621 static const char monetary[] = "MONETARY=";
622 static const char numeric[] = "NUMERIC=";
623 static const char time[] = "TIME=";
625 MSVCRT__locale_t loc;
626 LCID lcid[6] = { 0 };
627 char buf[256];
628 int i;
630 TRACE("(%d %s)\n", category, locale);
632 if(category<MSVCRT_LC_MIN || category>MSVCRT_LC_MAX || !locale)
633 return NULL;
635 if(locale[0]=='C' && !locale[1])
636 lcid[0] = CP_ACP;
637 else if(!locale[0])
638 lcid[0] = GetSystemDefaultLCID();
639 else if (locale[0] == 'L' && locale[1] == 'C' && locale[2] == '_') {
640 char *p;
642 while(1) {
643 locale += 3; /* LC_ */
644 if(!memcmp(locale, collate, sizeof(collate)-1)) {
645 i = MSVCRT_LC_COLLATE;
646 locale += sizeof(collate)-1;
647 } else if(!memcmp(locale, ctype, sizeof(ctype)-1)) {
648 i = MSVCRT_LC_CTYPE;
649 locale += sizeof(ctype)-1;
650 } else if(!memcmp(locale, monetary, sizeof(monetary)-1)) {
651 i = MSVCRT_LC_MONETARY;
652 locale += sizeof(monetary)-1;
653 } else if(!memcmp(locale, numeric, sizeof(numeric)-1)) {
654 i = MSVCRT_LC_NUMERIC;
655 locale += sizeof(numeric)-1;
656 } else if(!memcmp(locale, time, sizeof(time)-1)) {
657 i = MSVCRT_LC_TIME;
658 locale += sizeof(time)-1;
659 } else
660 return NULL;
662 p = strchr(locale, ';');
663 if(locale[0]=='C' && (locale[1]==';' || locale[1]=='\0'))
664 lcid[i] = 0;
665 else if(p) {
666 memcpy(buf, locale, p-locale);
667 lcid[i] = MSVCRT_locale_to_LCID(buf);
668 } else
669 lcid[i] = MSVCRT_locale_to_LCID(locale);
671 if(lcid[i] == -1)
672 return NULL;
674 if(!p || *(p+1)!='L' || *(p+2)!='C' || *(p+3)!='_')
675 break;
677 locale = p+1;
679 } else {
680 lcid[0] = MSVCRT_locale_to_LCID(locale);
681 if(lcid[0] == -1)
682 return NULL;
685 for(i=1; i<6; i++) {
686 if(!lcid[i])
687 lcid[i] = lcid[0];
690 loc = MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct));
691 if(!loc)
692 return NULL;
694 loc->locinfo = MSVCRT_malloc(sizeof(MSVCRT_threadlocinfo));
695 if(!loc->locinfo) {
696 MSVCRT_free(loc);
697 return NULL;
700 loc->mbcinfo = MSVCRT_malloc(sizeof(MSVCRT_threadmbcinfo));
701 if(!loc->mbcinfo) {
702 MSVCRT_free(loc->locinfo);
703 MSVCRT_free(loc);
704 return NULL;
707 memset(loc->locinfo, 0, sizeof(MSVCRT_threadlocinfo));
708 memset(loc->mbcinfo, 0, sizeof(MSVCRT_threadmbcinfo));
710 loc->locinfo->lconv = MSVCRT_malloc(sizeof(struct MSVCRT_lconv));
711 if(!loc->locinfo->lconv) {
712 MSVCRT__free_locale(loc);
713 return NULL;
715 memset(loc->locinfo->lconv, 0, sizeof(struct MSVCRT_lconv));
717 loc->locinfo->pclmap = MSVCRT_malloc(sizeof(char[256]));
718 loc->locinfo->pcumap = MSVCRT_malloc(sizeof(char[256]));
719 if(!loc->locinfo->pclmap || !loc->locinfo->pcumap) {
720 MSVCRT__free_locale(loc);
721 return NULL;
724 loc->locinfo->refcount = 1;
726 if(lcid[MSVCRT_LC_COLLATE] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_COLLATE)) {
727 if(update_threadlocinfo_category(lcid[MSVCRT_LC_COLLATE], loc, MSVCRT_LC_COLLATE)) {
728 MSVCRT__free_locale(loc);
729 return NULL;
731 } else
732 loc->locinfo->lc_category[MSVCRT_LC_COLLATE].locale = strdup("C");
734 if(lcid[MSVCRT_LC_CTYPE] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_CTYPE)) {
735 CPINFO cp;
737 if(update_threadlocinfo_category(lcid[MSVCRT_LC_CTYPE], loc, MSVCRT_LC_CTYPE)) {
738 MSVCRT__free_locale(loc);
739 return NULL;
742 loc->locinfo->lc_codepage = loc->locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage;
743 loc->locinfo->lc_collate_cp = loc->locinfo->lc_codepage;
744 loc->locinfo->lc_clike = 1;
745 if(!GetCPInfo(loc->locinfo->lc_codepage, &cp)) {
746 MSVCRT__free_locale(loc);
747 return NULL;
749 loc->locinfo->mb_cur_max = cp.MaxCharSize;
751 loc->locinfo->ctype1_refcount = MSVCRT_malloc(sizeof(int));
752 loc->locinfo->ctype1 = MSVCRT_malloc(sizeof(short[257]));
753 if(!loc->locinfo->ctype1_refcount || !loc->locinfo->ctype1) {
754 MSVCRT__free_locale(loc);
755 return NULL;
758 *loc->locinfo->ctype1_refcount = 1;
759 loc->locinfo->ctype1[0] = 0;
760 loc->locinfo->pctype = loc->locinfo->ctype1+1;
762 buf[1] = buf[2] = '\0';
763 for(i=1; i<257; i++) {
764 buf[0] = i-1;
766 GetStringTypeA(lcid[MSVCRT_LC_CTYPE], CT_CTYPE1, buf,
767 1, loc->locinfo->ctype1+i);
768 loc->locinfo->ctype1[i] |= 0x200;
770 } else {
771 loc->locinfo->lc_clike = 1;
772 loc->locinfo->mb_cur_max = 1;
773 loc->locinfo->pctype = MSVCRT__ctype+1;
774 loc->locinfo->lc_category[MSVCRT_LC_CTYPE].locale = strdup("C");
777 for(i=0; i<256; i++)
778 buf[i] = i;
780 LCMapStringA(lcid[MSVCRT_LC_CTYPE], LCMAP_LOWERCASE, buf, 256,
781 (char*)loc->locinfo->pclmap, 256);
782 LCMapStringA(lcid[MSVCRT_LC_CTYPE], LCMAP_UPPERCASE, buf, 256,
783 (char*)loc->locinfo->pcumap, 256);
785 loc->mbcinfo->refcount = 1;
786 loc->mbcinfo->mbcodepage = loc->locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage;
788 for(i=0; i<256; i++) {
789 if(loc->locinfo->pclmap[i] != i) {
790 loc->mbcinfo->mbctype[i+1] |= 0x10;
791 loc->mbcinfo->mbcasemap[i] = loc->locinfo->pclmap[i];
792 } else if(loc->locinfo->pcumap[i] != i) {
793 loc->mbcinfo->mbctype[i+1] |= 0x20;
794 loc->mbcinfo->mbcasemap[i] = loc->locinfo->pcumap[i];
798 if(lcid[MSVCRT_LC_MONETARY] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_MONETARY)) {
799 if(update_threadlocinfo_category(lcid[MSVCRT_LC_MONETARY], loc, MSVCRT_LC_MONETARY)) {
800 MSVCRT__free_locale(loc);
801 return NULL;
804 loc->locinfo->lconv_intl_refcount = MSVCRT_malloc(sizeof(int));
805 loc->locinfo->lconv_mon_refcount = MSVCRT_malloc(sizeof(int));
806 if(!loc->locinfo->lconv_intl_refcount || !loc->locinfo->lconv_mon_refcount) {
807 MSVCRT__free_locale(loc);
808 return NULL;
811 *loc->locinfo->lconv_intl_refcount = 1;
812 *loc->locinfo->lconv_mon_refcount = 1;
814 i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SINTLSYMBOL
815 |LOCALE_NOUSEROVERRIDE, buf, 256);
816 if(i && (loc->locinfo->lconv->int_curr_symbol = MSVCRT_malloc(sizeof(char[i]))))
817 memcpy(loc->locinfo->lconv->int_curr_symbol, buf, sizeof(char[i]));
818 else {
819 MSVCRT__free_locale(loc);
820 return NULL;
823 i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SCURRENCY
824 |LOCALE_NOUSEROVERRIDE, buf, 256);
825 if(i && (loc->locinfo->lconv->currency_symbol = MSVCRT_malloc(sizeof(char[i]))))
826 memcpy(loc->locinfo->lconv->currency_symbol, buf, sizeof(char[i]));
827 else {
828 MSVCRT__free_locale(loc);
829 return NULL;
832 i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONDECIMALSEP
833 |LOCALE_NOUSEROVERRIDE, buf, 256);
834 if(i && (loc->locinfo->lconv->mon_decimal_point = MSVCRT_malloc(sizeof(char[i]))))
835 memcpy(loc->locinfo->lconv->mon_decimal_point, buf, sizeof(char[i]));
836 else {
837 MSVCRT__free_locale(loc);
838 return NULL;
841 i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONTHOUSANDSEP
842 |LOCALE_NOUSEROVERRIDE, buf, 256);
843 if(i && (loc->locinfo->lconv->mon_thousands_sep = MSVCRT_malloc(sizeof(char[i]))))
844 memcpy(loc->locinfo->lconv->mon_thousands_sep, buf, sizeof(char[i]));
845 else {
846 MSVCRT__free_locale(loc);
847 return NULL;
850 i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONGROUPING
851 |LOCALE_NOUSEROVERRIDE, buf, 256);
852 if(i>1)
853 i = i/2 + (buf[i-2]=='0'?0:1);
854 if(i && (loc->locinfo->lconv->mon_grouping = MSVCRT_malloc(sizeof(char[i])))) {
855 for(i=0; buf[i+1]==';'; i+=2)
856 loc->locinfo->lconv->mon_grouping[i/2] = buf[i]-'0';
857 loc->locinfo->lconv->mon_grouping[i/2] = buf[i]-'0';
858 if(buf[i] != '0')
859 loc->locinfo->lconv->mon_grouping[i/2+1] = 127;
860 } else {
861 MSVCRT__free_locale(loc);
862 return NULL;
865 i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SPOSITIVESIGN
866 |LOCALE_NOUSEROVERRIDE, buf, 256);
867 if(i && (loc->locinfo->lconv->positive_sign = MSVCRT_malloc(sizeof(char[i]))))
868 memcpy(loc->locinfo->lconv->positive_sign, buf, sizeof(char[i]));
869 else {
870 MSVCRT__free_locale(loc);
871 return NULL;
874 i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SNEGATIVESIGN
875 |LOCALE_NOUSEROVERRIDE, buf, 256);
876 if(i && (loc->locinfo->lconv->negative_sign = MSVCRT_malloc(sizeof(char[i]))))
877 memcpy(loc->locinfo->lconv->negative_sign, buf, sizeof(char[i]));
878 else {
879 MSVCRT__free_locale(loc);
880 return NULL;
883 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IINTLCURRDIGITS
884 |LOCALE_NOUSEROVERRIDE, buf, 256))
885 loc->locinfo->lconv->int_frac_digits = atoi(buf);
886 else {
887 MSVCRT__free_locale(loc);
888 return NULL;
891 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_ICURRDIGITS
892 |LOCALE_NOUSEROVERRIDE, buf, 256))
893 loc->locinfo->lconv->frac_digits = atoi(buf);
894 else {
895 MSVCRT__free_locale(loc);
896 return NULL;
899 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSYMPRECEDES
900 |LOCALE_NOUSEROVERRIDE, buf, 256))
901 loc->locinfo->lconv->p_cs_precedes = atoi(buf);
902 else {
903 MSVCRT__free_locale(loc);
904 return NULL;
907 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSEPBYSPACE
908 |LOCALE_NOUSEROVERRIDE, buf, 256))
909 loc->locinfo->lconv->p_sep_by_space = atoi(buf);
910 else {
911 MSVCRT__free_locale(loc);
912 return NULL;
915 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSYMPRECEDES
916 |LOCALE_NOUSEROVERRIDE, buf, 256))
917 loc->locinfo->lconv->n_cs_precedes = atoi(buf);
918 else {
919 MSVCRT__free_locale(loc);
920 return NULL;
923 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSEPBYSPACE
924 |LOCALE_NOUSEROVERRIDE, buf, 256))
925 loc->locinfo->lconv->n_sep_by_space = atoi(buf);
926 else {
927 MSVCRT__free_locale(loc);
928 return NULL;
931 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSIGNPOSN
932 |LOCALE_NOUSEROVERRIDE, buf, 256))
933 loc->locinfo->lconv->p_sign_posn = atoi(buf);
934 else {
935 MSVCRT__free_locale(loc);
936 return NULL;
939 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSIGNPOSN
940 |LOCALE_NOUSEROVERRIDE, buf, 256))
941 loc->locinfo->lconv->n_sign_posn = atoi(buf);
942 else {
943 MSVCRT__free_locale(loc);
944 return NULL;
946 } else {
947 loc->locinfo->lconv->int_curr_symbol = MSVCRT_malloc(sizeof(char));
948 loc->locinfo->lconv->currency_symbol = MSVCRT_malloc(sizeof(char));
949 loc->locinfo->lconv->mon_decimal_point = MSVCRT_malloc(sizeof(char));
950 loc->locinfo->lconv->mon_thousands_sep = MSVCRT_malloc(sizeof(char));
951 loc->locinfo->lconv->mon_grouping = MSVCRT_malloc(sizeof(char));
952 loc->locinfo->lconv->positive_sign = MSVCRT_malloc(sizeof(char));
953 loc->locinfo->lconv->negative_sign = MSVCRT_malloc(sizeof(char));
955 if(!loc->locinfo->lconv->int_curr_symbol || !loc->locinfo->lconv->currency_symbol
956 || !loc->locinfo->lconv->mon_decimal_point || !loc->locinfo->lconv->mon_thousands_sep
957 || !loc->locinfo->lconv->mon_grouping || !loc->locinfo->lconv->positive_sign
958 || !loc->locinfo->lconv->negative_sign) {
959 MSVCRT__free_locale(loc);
960 return NULL;
963 loc->locinfo->lconv->int_curr_symbol[0] = '\0';
964 loc->locinfo->lconv->currency_symbol[0] = '\0';
965 loc->locinfo->lconv->mon_decimal_point[0] = '\0';
966 loc->locinfo->lconv->mon_thousands_sep[0] = '\0';
967 loc->locinfo->lconv->mon_grouping[0] = '\0';
968 loc->locinfo->lconv->positive_sign[0] = '\0';
969 loc->locinfo->lconv->negative_sign[0] = '\0';
970 loc->locinfo->lconv->int_frac_digits = 127;
971 loc->locinfo->lconv->frac_digits = 127;
972 loc->locinfo->lconv->p_cs_precedes = 127;
973 loc->locinfo->lconv->p_sep_by_space = 127;
974 loc->locinfo->lconv->n_cs_precedes = 127;
975 loc->locinfo->lconv->n_sep_by_space = 127;
976 loc->locinfo->lconv->p_sign_posn = 127;
977 loc->locinfo->lconv->n_sign_posn = 127;
979 loc->locinfo->lc_category[MSVCRT_LC_MONETARY].locale = strdup("C");
982 if(lcid[MSVCRT_LC_NUMERIC] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_NUMERIC)) {
983 if(update_threadlocinfo_category(lcid[MSVCRT_LC_NUMERIC], loc, MSVCRT_LC_NUMERIC)) {
984 MSVCRT__free_locale(loc);
985 return NULL;
988 if(!loc->locinfo->lconv_intl_refcount)
989 loc->locinfo->lconv_intl_refcount = MSVCRT_malloc(sizeof(int));
990 loc->locinfo->lconv_num_refcount = MSVCRT_malloc(sizeof(int));
991 if(!loc->locinfo->lconv_intl_refcount || !loc->locinfo->lconv_num_refcount) {
992 MSVCRT__free_locale(loc);
993 return NULL;
996 *loc->locinfo->lconv_intl_refcount = 1;
997 *loc->locinfo->lconv_num_refcount = 1;
999 i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_SDECIMAL
1000 |LOCALE_NOUSEROVERRIDE, buf, 256);
1001 if(i && (loc->locinfo->lconv->decimal_point = MSVCRT_malloc(sizeof(char[i]))))
1002 memcpy(loc->locinfo->lconv->decimal_point, buf, sizeof(char[i]));
1003 else {
1004 MSVCRT__free_locale(loc);
1005 return NULL;
1008 i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_STHOUSAND
1009 |LOCALE_NOUSEROVERRIDE, buf, 256);
1010 if(i && (loc->locinfo->lconv->thousands_sep = MSVCRT_malloc(sizeof(char[i]))))
1011 memcpy(loc->locinfo->lconv->thousands_sep, buf, sizeof(char[i]));
1012 else {
1013 MSVCRT__free_locale(loc);
1014 return NULL;
1017 i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_SGROUPING
1018 |LOCALE_NOUSEROVERRIDE, buf, 256);
1019 if(i>1)
1020 i = i/2 + (buf[i-2]=='0'?0:1);
1021 if(i && (loc->locinfo->lconv->grouping = MSVCRT_malloc(sizeof(char[i])))) {
1022 for(i=0; buf[i+1]==';'; i+=2)
1023 loc->locinfo->lconv->grouping[i/2] = buf[i]-'0';
1024 loc->locinfo->lconv->grouping[i/2] = buf[i]-'0';
1025 if(buf[i] != '0')
1026 loc->locinfo->lconv->grouping[i/2+1] = 127;
1027 } else {
1028 MSVCRT__free_locale(loc);
1029 return NULL;
1031 } else {
1032 loc->locinfo->lconv->decimal_point = MSVCRT_malloc(sizeof(char[2]));
1033 loc->locinfo->lconv->thousands_sep = MSVCRT_malloc(sizeof(char));
1034 loc->locinfo->lconv->grouping = MSVCRT_malloc(sizeof(char));
1035 if(!loc->locinfo->lconv->decimal_point || !loc->locinfo->lconv->thousands_sep
1036 || !loc->locinfo->lconv->grouping) {
1037 MSVCRT__free_locale(loc);
1038 return NULL;
1041 loc->locinfo->lconv->decimal_point[0] = '.';
1042 loc->locinfo->lconv->decimal_point[1] = '\0';
1043 loc->locinfo->lconv->thousands_sep[0] = '\0';
1044 loc->locinfo->lconv->grouping[0] = '\0';
1046 loc->locinfo->lc_category[MSVCRT_LC_NUMERIC].locale = strdup("C");
1049 if(lcid[MSVCRT_LC_TIME] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_TIME)) {
1050 if(update_threadlocinfo_category(lcid[MSVCRT_LC_TIME], loc, MSVCRT_LC_TIME)) {
1051 MSVCRT__free_locale(loc);
1052 return NULL;
1054 } else
1055 loc->locinfo->lc_category[MSVCRT_LC_TIME].locale = strdup("C");
1057 return loc;
1060 /* _configthreadlocale - not exported in native msvcrt */
1061 int CDECL _configthreadlocale(int type)
1063 thread_data_t *data = msvcrt_get_thread_data();
1064 int ret;
1066 if(!data)
1067 return -1;
1069 ret = (data->locale ? MSVCRT__ENABLE_PER_THREAD_LOCALE : MSVCRT__DISABLE_PER_THREAD_LOCALE);
1071 if(type == MSVCRT__ENABLE_PER_THREAD_LOCALE) {
1072 if(!data->locale) {
1073 /* Copy current global locale */
1074 data->locale = MSVCRT__create_locale(MSVCRT_LC_ALL, MSVCRT_setlocale(MSVCRT_LC_ALL, NULL));
1075 if(!data->locale)
1076 return -1;
1079 return ret;
1082 if(type == MSVCRT__DISABLE_PER_THREAD_LOCALE) {
1083 if(data->locale) {
1084 MSVCRT__free_locale(data->locale);
1085 data->locale = NULL;
1088 return ret;
1091 if(!type)
1092 return ret;
1094 return -1;
1097 /*********************************************************************
1098 * setlocale (MSVCRT.@)
1100 char* CDECL MSVCRT_setlocale(int category, const char* locale)
1102 MSVCRT__locale_t loc, cur;
1104 cur = get_locale();
1106 if(category<MSVCRT_LC_MIN || category>MSVCRT_LC_MAX)
1107 return NULL;
1109 if(!locale) {
1110 if(category == MSVCRT_LC_ALL)
1111 return construct_lc_all(cur);
1113 return cur->locinfo->lc_category[category].locale;
1116 loc = MSVCRT__create_locale(category, locale);
1117 if(!loc) {
1118 WARN("%d %s failed\n", category, locale);
1119 return NULL;
1122 LOCK_LOCALE;
1124 switch(category) {
1125 case MSVCRT_LC_ALL:
1126 if(!cur)
1127 break;
1128 case MSVCRT_LC_COLLATE:
1129 cur->locinfo->lc_handle[MSVCRT_LC_COLLATE] =
1130 loc->locinfo->lc_handle[MSVCRT_LC_COLLATE];
1131 swap_pointers((void**)&cur->locinfo->lc_category[MSVCRT_LC_COLLATE].locale,
1132 (void**)&loc->locinfo->lc_category[MSVCRT_LC_COLLATE].locale);
1133 swap_pointers((void**)&cur->locinfo->lc_category[MSVCRT_LC_COLLATE].refcount,
1134 (void**)&loc->locinfo->lc_category[MSVCRT_LC_COLLATE].refcount);
1136 if(category != MSVCRT_LC_ALL)
1137 break;
1138 case MSVCRT_LC_CTYPE:
1139 cur->locinfo->lc_handle[MSVCRT_LC_CTYPE] =
1140 loc->locinfo->lc_handle[MSVCRT_LC_CTYPE];
1141 swap_pointers((void**)&cur->locinfo->lc_category[MSVCRT_LC_CTYPE].locale,
1142 (void**)&loc->locinfo->lc_category[MSVCRT_LC_CTYPE].locale);
1143 swap_pointers((void**)&cur->locinfo->lc_category[MSVCRT_LC_CTYPE].refcount,
1144 (void**)&loc->locinfo->lc_category[MSVCRT_LC_CTYPE].refcount);
1146 cur->locinfo->lc_codepage = loc->locinfo->lc_codepage;
1147 cur->locinfo->lc_collate_cp = loc->locinfo->lc_collate_cp;
1148 cur->locinfo->lc_clike = loc->locinfo->lc_clike;
1149 cur->locinfo->mb_cur_max = loc->locinfo->mb_cur_max;
1151 swap_pointers((void**)&cur->locinfo->ctype1_refcount,
1152 (void**)&loc->locinfo->ctype1_refcount);
1153 swap_pointers((void**)&cur->locinfo->ctype1, (void**)&loc->locinfo->ctype1);
1154 swap_pointers((void**)&cur->locinfo->pctype, (void**)&loc->locinfo->pctype);
1155 swap_pointers((void**)&cur->locinfo->pclmap, (void**)&loc->locinfo->pclmap);
1156 swap_pointers((void**)&cur->locinfo->pcumap, (void**)&loc->locinfo->pcumap);
1158 memcpy(cur->mbcinfo, loc->mbcinfo, sizeof(MSVCRT_threadmbcinfo));
1160 if(category != MSVCRT_LC_ALL)
1161 break;
1162 case MSVCRT_LC_MONETARY:
1163 cur->locinfo->lc_handle[MSVCRT_LC_MONETARY] =
1164 loc->locinfo->lc_handle[MSVCRT_LC_MONETARY];
1165 swap_pointers((void**)&cur->locinfo->lc_category[MSVCRT_LC_MONETARY].locale,
1166 (void**)&loc->locinfo->lc_category[MSVCRT_LC_MONETARY].locale);
1167 swap_pointers((void**)&cur->locinfo->lc_category[MSVCRT_LC_MONETARY].refcount,
1168 (void**)&loc->locinfo->lc_category[MSVCRT_LC_MONETARY].refcount);
1170 swap_pointers((void**)&cur->locinfo->lconv->int_curr_symbol,
1171 (void**)&loc->locinfo->lconv->int_curr_symbol);
1172 swap_pointers((void**)&cur->locinfo->lconv->currency_symbol,
1173 (void**)&loc->locinfo->lconv->currency_symbol);
1174 swap_pointers((void**)&cur->locinfo->lconv->mon_decimal_point,
1175 (void**)&loc->locinfo->lconv->mon_decimal_point);
1176 swap_pointers((void**)&cur->locinfo->lconv->mon_thousands_sep,
1177 (void**)&loc->locinfo->lconv->mon_thousands_sep);
1178 swap_pointers((void**)&cur->locinfo->lconv->mon_grouping,
1179 (void**)&loc->locinfo->lconv->mon_grouping);
1180 swap_pointers((void**)&cur->locinfo->lconv->positive_sign,
1181 (void**)&loc->locinfo->lconv->positive_sign);
1182 swap_pointers((void**)&cur->locinfo->lconv->negative_sign,
1183 (void**)&loc->locinfo->lconv->negative_sign);
1184 cur->locinfo->lconv->int_frac_digits = loc->locinfo->lconv->int_frac_digits;
1185 cur->locinfo->lconv->frac_digits = loc->locinfo->lconv->frac_digits;
1186 cur->locinfo->lconv->p_cs_precedes = loc->locinfo->lconv->p_cs_precedes;
1187 cur->locinfo->lconv->p_sep_by_space = loc->locinfo->lconv->p_sep_by_space;
1188 cur->locinfo->lconv->n_cs_precedes = loc->locinfo->lconv->n_cs_precedes;
1189 cur->locinfo->lconv->n_sep_by_space = loc->locinfo->lconv->n_sep_by_space;
1190 cur->locinfo->lconv->p_sign_posn = loc->locinfo->lconv->p_sign_posn;
1191 cur->locinfo->lconv->n_sign_posn = loc->locinfo->lconv->n_sign_posn;
1193 if(category != MSVCRT_LC_ALL)
1194 break;
1195 case MSVCRT_LC_NUMERIC:
1196 cur->locinfo->lc_handle[MSVCRT_LC_NUMERIC] =
1197 loc->locinfo->lc_handle[MSVCRT_LC_NUMERIC];
1198 swap_pointers((void**)&cur->locinfo->lc_category[MSVCRT_LC_NUMERIC].locale,
1199 (void**)&loc->locinfo->lc_category[MSVCRT_LC_NUMERIC].locale);
1200 swap_pointers((void**)&cur->locinfo->lc_category[MSVCRT_LC_NUMERIC].refcount,
1201 (void**)&loc->locinfo->lc_category[MSVCRT_LC_NUMERIC].refcount);
1203 swap_pointers((void**)&cur->locinfo->lconv->decimal_point,
1204 (void**)&loc->locinfo->lconv->decimal_point);
1205 swap_pointers((void**)&cur->locinfo->lconv->thousands_sep,
1206 (void**)&loc->locinfo->lconv->thousands_sep);
1207 swap_pointers((void**)&cur->locinfo->lconv->grouping,
1208 (void**)&loc->locinfo->lconv->grouping);
1210 if(category != MSVCRT_LC_ALL)
1211 break;
1212 case MSVCRT_LC_TIME:
1213 cur->locinfo->lc_handle[MSVCRT_LC_TIME] =
1214 loc->locinfo->lc_handle[MSVCRT_LC_TIME];
1215 swap_pointers((void**)&cur->locinfo->lc_category[MSVCRT_LC_TIME].locale,
1216 (void**)&loc->locinfo->lc_category[MSVCRT_LC_TIME].locale);
1217 swap_pointers((void**)&cur->locinfo->lc_category[MSVCRT_LC_TIME].refcount,
1218 (void**)&loc->locinfo->lc_category[MSVCRT_LC_TIME].refcount);
1220 if(category != MSVCRT_LC_ALL)
1221 break;
1224 if(!cur)
1225 MSVCRT_locale = cur = loc;
1226 else
1227 MSVCRT__free_locale(loc);
1229 UNLOCK_LOCALE;
1231 if(cur == MSVCRT_locale) {
1232 MSVCRT___lc_codepage = cur->locinfo->lc_codepage;
1233 MSVCRT___lc_collate_cp = cur->locinfo->lc_collate_cp;
1234 MSVCRT___mb_cur_max = cur->locinfo->mb_cur_max;
1235 MSVCRT__pctype = cur->locinfo->pctype;
1238 if(category == MSVCRT_LC_ALL)
1239 return construct_lc_all(cur);
1241 return cur->locinfo->lc_category[category].locale;