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
22 #include "wine/port.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 LCID MSVCRT___lc_handle[MSVCRT_LC_MAX - MSVCRT_LC_MIN + 1] = { 0 };
47 static unsigned char charmax = CHAR_MAX;
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[] =
60 "american english", "enu",
61 "american-english", "enu",
62 "english-american", "enu",
70 "french-belgian", "frb",
73 "french-canadian", "frc",
75 "chinese-simplified", "chs",
76 "chinese-traditional", "cht",
77 "dutch-belgian", "nlb",
81 "french-swiss", "frs",
83 "german-swiss", "des",
84 "italian-swiss", "its",
85 "german-austrian", "dea",
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)
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]));
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
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;
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)
132 GetLocaleInfoA(lcid, flags|LOCALE_NOUSEROVERRIDE, buff, MAX_ELEM_LEN);
133 if (!buff[0] || !cmp[0])
136 /* Partial matches are only allowed on language/country names */
139 return !strcasecmp(cmp, buff);
141 return !strncasecmp(cmp, buff, len);
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;
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;
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;
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");
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)
215 locale_search_t search;
216 const 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);
225 lstrcpynA(search.search_country, region+1, MAX_ELEM_LEN);
226 if(region-locale < MAX_ELEM_LEN)
227 search.search_language[region-locale] = '\0';
229 search.search_country[0] = '\0';
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';
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,
247 if (!search.match_flags)
250 /* If we were given something that didn't match, fail */
251 if (search.search_country[0] && !(search.match_flags & FOUND_COUNTRY))
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);
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);
274 if (!atoi(search.found_codepage))
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);
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)
296 if(GetLocaleInfoA(lcid, LOCALE_ILANGUAGE|LOCALE_NOUSEROVERRIDE, buf, 256)) {
299 loc->locinfo->lc_id[category].wLanguage = 0;
301 loc->locinfo->lc_id[category].wLanguage *= 16;
304 loc->locinfo->lc_id[category].wLanguage += *p-'0';
306 loc->locinfo->lc_id[category].wLanguage += *p-'a'+10;
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;
322 len += GetLocaleInfoA(lcid, LOCALE_SENGLANGUAGE
323 |LOCALE_NOUSEROVERRIDE, buf, 256);
325 len += GetLocaleInfoA(lcid, LOCALE_SENGCOUNTRY
326 |LOCALE_NOUSEROVERRIDE, &buf[len], 256-len);
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;
341 memcpy(loc->locinfo->lc_category[category].locale, buf, sizeof(char[len]));
342 *loc->locinfo->lc_category[category].refcount = 1;
347 /* INTERNAL: swap pointers values */
348 static inline void swap_pointers(void **p1, void **p2) {
356 /* INTERNAL: returns pthreadlocinfo struct */
357 MSVCRT_pthreadlocinfo get_locinfo(void) {
358 thread_data_t *data = msvcrt_get_thread_data();
360 if(!data || !data->have_locale)
361 return MSVCRT_locale->locinfo;
363 return data->locinfo;
366 /* INTERNAL: returns pthreadlocinfo struct */
367 static MSVCRT_pthreadmbcinfo get_mbcinfo(void) {
368 thread_data_t *data = msvcrt_get_thread_data();
370 if(!data || !data->have_locale)
371 return MSVCRT_locale->mbcinfo;
373 return data->mbcinfo;
376 /* INTERNAL: constructs string returned by setlocale */
377 static inline char* construct_lc_all(MSVCRT_pthreadlocinfo locinfo) {
378 static char current_lc_all[MAX_LOCALE_LENGTH];
382 for(i=MSVCRT_LC_MIN+1; i<MSVCRT_LC_MAX; i++) {
383 if(strcmp(locinfo->lc_category[i].locale,
384 locinfo->lc_category[i+1].locale))
389 return locinfo->lc_category[MSVCRT_LC_COLLATE].locale;
391 sprintf(current_lc_all,
392 "LC_COLLATE=%s;LC_CTYPE=%s;LC_MONETARY=%s;LC_NUMERIC=%s;LC_TIME=%s",
393 locinfo->lc_category[MSVCRT_LC_COLLATE].locale,
394 locinfo->lc_category[MSVCRT_LC_CTYPE].locale,
395 locinfo->lc_category[MSVCRT_LC_MONETARY].locale,
396 locinfo->lc_category[MSVCRT_LC_NUMERIC].locale,
397 locinfo->lc_category[MSVCRT_LC_TIME].locale);
399 return current_lc_all;
403 /*********************************************************************
404 * wsetlocale (MSVCRT.@)
406 MSVCRT_wchar_t* CDECL MSVCRT__wsetlocale(int category, const MSVCRT_wchar_t* locale)
408 static MSVCRT_wchar_t fake[] = {
409 'E','n','g','l','i','s','h','_','U','n','i','t','e','d',' ',
410 'S','t','a','t','e','s','.','1','2','5','2',0 };
412 FIXME("%d %s\n", category, debugstr_w(locale));
417 /*********************************************************************
418 * _Getdays (MSVCRT.@)
420 const char* CDECL _Getdays(void)
422 static const char MSVCRT_days[] = ":Sun:Sunday:Mon:Monday:Tue:Tuesday:Wed:"
423 "Wednesday:Thu:Thursday:Fri:Friday:Sat:Saturday";
424 /* FIXME: Use locale */
425 TRACE("(void) semi-stub\n");
429 /*********************************************************************
430 * _Getmonths (MSVCRT.@)
432 const char* CDECL _Getmonths(void)
434 static const char MSVCRT_months[] = ":Jan:January:Feb:February:Mar:March:Apr:"
435 "April:May:May:Jun:June:Jul:July:Aug:August:Sep:September:Oct:"
436 "October:Nov:November:Dec:December";
437 /* FIXME: Use locale */
438 TRACE("(void) semi-stub\n");
439 return MSVCRT_months;
442 /*********************************************************************
443 * _Gettnames (MSVCRT.@)
445 const char* CDECL _Gettnames(void)
448 TRACE("(void) stub\n");
452 /*********************************************************************
453 * _Strftime (MSVCRT.@)
455 const char* CDECL _Strftime(char *out, unsigned int len, const char *fmt,
456 const void *tm, void *foo)
459 TRACE("(%p %d %s %p %p) stub\n", out, len, fmt, tm, foo);
463 /*********************************************************************
464 * __crtLCMapStringA (MSVCRT.@)
466 int CDECL __crtLCMapStringA(
467 LCID lcid, DWORD mapflags, const char* src, int srclen, char* dst,
468 int dstlen, unsigned int codepage, int xflag
470 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
471 lcid,mapflags,src,srclen,dst,dstlen,codepage,xflag);
472 /* FIXME: A bit incorrect. But msvcrt itself just converts its
473 * arguments to wide strings and then calls LCMapStringW
475 return LCMapStringA(lcid,mapflags,src,srclen,dst,dstlen);
478 /*********************************************************************
479 * __crtLCMapStringW (MSVCRT.@)
481 int CDECL __crtLCMapStringW(LCID lcid, DWORD mapflags, const MSVCRT_wchar_t *src,
482 int srclen, MSVCRT_wchar_t *dst, int dstlen, unsigned int codepage, int xflag)
484 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
485 lcid, mapflags, debugstr_w(src), srclen, dst, dstlen, codepage, xflag);
487 return LCMapStringW(lcid, mapflags, src, srclen, dst, dstlen);
490 /*********************************************************************
491 * __crtCompareStringA (MSVCRT.@)
493 int CDECL __crtCompareStringA( LCID lcid, DWORD flags, const char *src1, int len1,
494 const char *src2, int len2 )
496 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
497 lcid, flags, debugstr_a(src1), len1, debugstr_a(src2), len2 );
498 /* FIXME: probably not entirely right */
499 return CompareStringA( lcid, flags, src1, len1, src2, len2 );
502 /*********************************************************************
503 * __crtCompareStringW (MSVCRT.@)
505 int CDECL __crtCompareStringW( LCID lcid, DWORD flags, const MSVCRT_wchar_t *src1, int len1,
506 const MSVCRT_wchar_t *src2, int len2 )
508 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
509 lcid, flags, debugstr_w(src1), len1, debugstr_w(src2), len2 );
510 /* FIXME: probably not entirely right */
511 return CompareStringW( lcid, flags, src1, len1, src2, len2 );
514 /*********************************************************************
515 * __crtGetLocaleInfoW (MSVCRT.@)
517 int CDECL __crtGetLocaleInfoW( LCID lcid, LCTYPE type, MSVCRT_wchar_t *buffer, int len )
519 FIXME("(lcid %x, type %x, %p(%d), partial stub\n", lcid, type, buffer, len );
520 /* FIXME: probably not entirely right */
521 return GetLocaleInfoW( lcid, type, buffer, len );
524 /*********************************************************************
527 MSVCRT_wint_t CDECL MSVCRT_btowc(int c)
529 unsigned char letter = c;
532 if(!MultiByteToWideChar(get_locinfo()->lc_handle[MSVCRT_LC_CTYPE],
533 0, (LPCSTR)&letter, 1, &ret, 1))
539 /*********************************************************************
540 * __crtGetStringTypeW(MSVCRT.@)
542 * This function was accepting different number of arguments in older
543 * versions of msvcrt.
545 BOOL CDECL __crtGetStringTypeW(DWORD unk, DWORD type,
546 MSVCRT_wchar_t *buffer, int len, WORD *out)
548 FIXME("(unk %x, type %x, wstr %p(%d), %p) partial stub\n",
549 unk, type, buffer, len, out);
551 return GetStringTypeW(type, buffer, len, out);
554 /*********************************************************************
555 * localeconv (MSVCRT.@)
557 struct MSVCRT_lconv * CDECL MSVCRT_localeconv(void)
559 return get_locinfo()->lconv;
562 /*********************************************************************
563 * __lconv_init (MSVCRT.@)
565 int CDECL __lconv_init(void)
567 /* this is used to make chars unsigned */
572 /*********************************************************************
573 * ___lc_handle_func (MSVCRT.@)
575 LCID* CDECL ___lc_handle_func(void)
577 return MSVCRT___lc_handle;
580 /*********************************************************************
581 * ___lc_codepage_func (MSVCRT.@)
583 int CDECL ___lc_codepage_func(void)
585 return MSVCRT___lc_codepage;
588 /*********************************************************************
589 * ___lc_collate_cp_func (MSVCRT.@)
591 int CDECL ___lc_collate_cp_func(void)
593 return get_locinfo()->lc_collate_cp;
596 /* INTERNAL: frees MSVCRT_pthreadlocinfo struct */
597 void free_locinfo(MSVCRT_pthreadlocinfo locinfo)
604 for(i=MSVCRT_LC_MIN+1; i<=MSVCRT_LC_MAX; i++) {
605 MSVCRT_free(locinfo->lc_category[i].locale);
606 MSVCRT_free(locinfo->lc_category[i].refcount);
610 MSVCRT_free(locinfo->lconv->decimal_point);
611 MSVCRT_free(locinfo->lconv->thousands_sep);
612 MSVCRT_free(locinfo->lconv->grouping);
613 MSVCRT_free(locinfo->lconv->int_curr_symbol);
614 MSVCRT_free(locinfo->lconv->currency_symbol);
615 MSVCRT_free(locinfo->lconv->mon_decimal_point);
616 MSVCRT_free(locinfo->lconv->mon_thousands_sep);
617 MSVCRT_free(locinfo->lconv->mon_grouping);
618 MSVCRT_free(locinfo->lconv->positive_sign);
619 MSVCRT_free(locinfo->lconv->negative_sign);
621 MSVCRT_free(locinfo->lconv_intl_refcount);
622 MSVCRT_free(locinfo->lconv_num_refcount);
623 MSVCRT_free(locinfo->lconv_mon_refcount);
624 MSVCRT_free(locinfo->lconv);
626 MSVCRT_free(locinfo->ctype1_refcount);
627 MSVCRT_free(locinfo->ctype1);
629 MSVCRT_free(locinfo->pclmap);
630 MSVCRT_free(locinfo->pcumap);
632 MSVCRT_free(locinfo);
635 /* INTERNAL: frees MSVCRT_pthreadmbcinfo struct */
636 void free_mbcinfo(MSVCRT_pthreadmbcinfo mbcinfo)
641 MSVCRT_free(mbcinfo);
644 /* _free_locale - not exported in native msvcrt */
645 void CDECL MSVCRT__free_locale(MSVCRT__locale_t locale)
650 free_locinfo(locale->locinfo);
651 free_mbcinfo(locale->mbcinfo);
655 /* _create_locale - not exported in native msvcrt */
656 MSVCRT__locale_t MSVCRT__create_locale(int category, const char *locale)
658 static const char collate[] = "COLLATE=";
659 static const char ctype[] = "CTYPE=";
660 static const char monetary[] = "MONETARY=";
661 static const char numeric[] = "NUMERIC=";
662 static const char time[] = "TIME=";
664 MSVCRT__locale_t loc;
665 LCID lcid[6] = { 0 };
669 TRACE("(%d %s)\n", category, locale);
671 if(category<MSVCRT_LC_MIN || category>MSVCRT_LC_MAX || !locale)
674 if(locale[0]=='C' && !locale[1])
677 lcid[0] = GetSystemDefaultLCID();
678 else if (locale[0] == 'L' && locale[1] == 'C' && locale[2] == '_') {
682 locale += 3; /* LC_ */
683 if(!memcmp(locale, collate, sizeof(collate)-1)) {
684 i = MSVCRT_LC_COLLATE;
685 locale += sizeof(collate)-1;
686 } else if(!memcmp(locale, ctype, sizeof(ctype)-1)) {
688 locale += sizeof(ctype)-1;
689 } else if(!memcmp(locale, monetary, sizeof(monetary)-1)) {
690 i = MSVCRT_LC_MONETARY;
691 locale += sizeof(monetary)-1;
692 } else if(!memcmp(locale, numeric, sizeof(numeric)-1)) {
693 i = MSVCRT_LC_NUMERIC;
694 locale += sizeof(numeric)-1;
695 } else if(!memcmp(locale, time, sizeof(time)-1)) {
697 locale += sizeof(time)-1;
701 p = strchr(locale, ';');
702 if(locale[0]=='C' && (locale[1]==';' || locale[1]=='\0'))
705 memcpy(buf, locale, p-locale);
706 buf[p-locale] = '\0';
707 lcid[i] = MSVCRT_locale_to_LCID(buf);
709 lcid[i] = MSVCRT_locale_to_LCID(locale);
714 if(!p || *(p+1)!='L' || *(p+2)!='C' || *(p+3)!='_')
720 lcid[0] = MSVCRT_locale_to_LCID(locale);
730 loc = MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct));
734 loc->locinfo = MSVCRT_malloc(sizeof(MSVCRT_threadlocinfo));
740 loc->mbcinfo = MSVCRT_malloc(sizeof(MSVCRT_threadmbcinfo));
742 MSVCRT_free(loc->locinfo);
747 memset(loc->locinfo, 0, sizeof(MSVCRT_threadlocinfo));
748 memset(loc->mbcinfo, 0, sizeof(MSVCRT_threadmbcinfo));
750 loc->locinfo->lconv = MSVCRT_malloc(sizeof(struct MSVCRT_lconv));
751 if(!loc->locinfo->lconv) {
752 MSVCRT__free_locale(loc);
755 memset(loc->locinfo->lconv, 0, sizeof(struct MSVCRT_lconv));
757 loc->locinfo->pclmap = MSVCRT_malloc(sizeof(char[256]));
758 loc->locinfo->pcumap = MSVCRT_malloc(sizeof(char[256]));
759 if(!loc->locinfo->pclmap || !loc->locinfo->pcumap) {
760 MSVCRT__free_locale(loc);
764 loc->locinfo->refcount = 1;
766 if(lcid[MSVCRT_LC_COLLATE] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_COLLATE)) {
767 if(update_threadlocinfo_category(lcid[MSVCRT_LC_COLLATE], loc, MSVCRT_LC_COLLATE)) {
768 MSVCRT__free_locale(loc);
772 loc->locinfo->lc_category[MSVCRT_LC_COLLATE].locale = MSVCRT__strdup("C");
774 if(lcid[MSVCRT_LC_CTYPE] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_CTYPE)) {
778 if(update_threadlocinfo_category(lcid[MSVCRT_LC_CTYPE], loc, MSVCRT_LC_CTYPE)) {
779 MSVCRT__free_locale(loc);
783 loc->locinfo->lc_codepage = loc->locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage;
784 loc->locinfo->lc_collate_cp = loc->locinfo->lc_codepage;
785 loc->locinfo->lc_clike = 1;
786 if(!GetCPInfo(loc->locinfo->lc_codepage, &cp)) {
787 MSVCRT__free_locale(loc);
790 loc->locinfo->mb_cur_max = cp.MaxCharSize;
792 loc->locinfo->ctype1_refcount = MSVCRT_malloc(sizeof(int));
793 loc->locinfo->ctype1 = MSVCRT_malloc(sizeof(short[257]));
794 if(!loc->locinfo->ctype1_refcount || !loc->locinfo->ctype1) {
795 MSVCRT__free_locale(loc);
799 *loc->locinfo->ctype1_refcount = 1;
800 loc->locinfo->ctype1[0] = 0;
801 loc->locinfo->pctype = loc->locinfo->ctype1+1;
803 buf[1] = buf[2] = '\0';
804 for(i=1; i<257; i++) {
807 GetStringTypeA(lcid[MSVCRT_LC_CTYPE], CT_CTYPE1, buf,
808 1, loc->locinfo->ctype1+i);
811 for(i=0; cp.LeadByte[i+1]!=0; i+=2)
812 for(j=cp.LeadByte[i]; j<=cp.LeadByte[i+1]; j++)
813 loc->locinfo->ctype1[j+1] |= MSVCRT__LEADBYTE;
815 loc->locinfo->lc_clike = 1;
816 loc->locinfo->mb_cur_max = 1;
817 loc->locinfo->pctype = MSVCRT__ctype+1;
818 loc->locinfo->lc_category[MSVCRT_LC_CTYPE].locale = MSVCRT__strdup("C");
821 for(i=0; i<256; i++) {
822 if(loc->locinfo->pctype[i] & MSVCRT__LEADBYTE)
829 if(lcid[MSVCRT_LC_CTYPE]) {
830 LCMapStringA(lcid[MSVCRT_LC_CTYPE], LCMAP_LOWERCASE, buf, 256,
831 (char*)loc->locinfo->pclmap, 256);
832 LCMapStringA(lcid[MSVCRT_LC_CTYPE], LCMAP_UPPERCASE, buf, 256,
833 (char*)loc->locinfo->pcumap, 256);
835 for(i=0; i<256; i++) {
836 loc->locinfo->pclmap[i] = (i>='A' && i<='Z' ? i-'A'+'a' : i);
837 loc->locinfo->pcumap[i] = (i>='a' && i<='z' ? i-'a'+'A' : i);
841 loc->mbcinfo->refcount = 1;
842 loc->mbcinfo->mbcodepage = loc->locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage;
844 for(i=0; i<256; i++) {
845 if(loc->locinfo->pclmap[i] != i) {
846 loc->mbcinfo->mbctype[i+1] |= 0x10;
847 loc->mbcinfo->mbcasemap[i] = loc->locinfo->pclmap[i];
848 } else if(loc->locinfo->pcumap[i] != i) {
849 loc->mbcinfo->mbctype[i+1] |= 0x20;
850 loc->mbcinfo->mbcasemap[i] = loc->locinfo->pcumap[i];
854 if(lcid[MSVCRT_LC_MONETARY] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_MONETARY)) {
855 if(update_threadlocinfo_category(lcid[MSVCRT_LC_MONETARY], loc, MSVCRT_LC_MONETARY)) {
856 MSVCRT__free_locale(loc);
860 loc->locinfo->lconv_intl_refcount = MSVCRT_malloc(sizeof(int));
861 loc->locinfo->lconv_mon_refcount = MSVCRT_malloc(sizeof(int));
862 if(!loc->locinfo->lconv_intl_refcount || !loc->locinfo->lconv_mon_refcount) {
863 MSVCRT__free_locale(loc);
867 *loc->locinfo->lconv_intl_refcount = 1;
868 *loc->locinfo->lconv_mon_refcount = 1;
870 i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SINTLSYMBOL
871 |LOCALE_NOUSEROVERRIDE, buf, 256);
872 if(i && (loc->locinfo->lconv->int_curr_symbol = MSVCRT_malloc(sizeof(char[i]))))
873 memcpy(loc->locinfo->lconv->int_curr_symbol, buf, sizeof(char[i]));
875 MSVCRT__free_locale(loc);
879 i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SCURRENCY
880 |LOCALE_NOUSEROVERRIDE, buf, 256);
881 if(i && (loc->locinfo->lconv->currency_symbol = MSVCRT_malloc(sizeof(char[i]))))
882 memcpy(loc->locinfo->lconv->currency_symbol, buf, sizeof(char[i]));
884 MSVCRT__free_locale(loc);
888 i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONDECIMALSEP
889 |LOCALE_NOUSEROVERRIDE, buf, 256);
890 if(i && (loc->locinfo->lconv->mon_decimal_point = MSVCRT_malloc(sizeof(char[i]))))
891 memcpy(loc->locinfo->lconv->mon_decimal_point, buf, sizeof(char[i]));
893 MSVCRT__free_locale(loc);
897 i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONTHOUSANDSEP
898 |LOCALE_NOUSEROVERRIDE, buf, 256);
899 if(i && (loc->locinfo->lconv->mon_thousands_sep = MSVCRT_malloc(sizeof(char[i]))))
900 memcpy(loc->locinfo->lconv->mon_thousands_sep, buf, sizeof(char[i]));
902 MSVCRT__free_locale(loc);
906 i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONGROUPING
907 |LOCALE_NOUSEROVERRIDE, buf, 256);
909 i = i/2 + (buf[i-2]=='0'?0:1);
910 if(i && (loc->locinfo->lconv->mon_grouping = MSVCRT_malloc(sizeof(char[i])))) {
911 for(i=0; buf[i+1]==';'; i+=2)
912 loc->locinfo->lconv->mon_grouping[i/2] = buf[i]-'0';
913 loc->locinfo->lconv->mon_grouping[i/2] = buf[i]-'0';
915 loc->locinfo->lconv->mon_grouping[i/2+1] = 127;
917 MSVCRT__free_locale(loc);
921 i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SPOSITIVESIGN
922 |LOCALE_NOUSEROVERRIDE, buf, 256);
923 if(i && (loc->locinfo->lconv->positive_sign = MSVCRT_malloc(sizeof(char[i]))))
924 memcpy(loc->locinfo->lconv->positive_sign, buf, sizeof(char[i]));
926 MSVCRT__free_locale(loc);
930 i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SNEGATIVESIGN
931 |LOCALE_NOUSEROVERRIDE, buf, 256);
932 if(i && (loc->locinfo->lconv->negative_sign = MSVCRT_malloc(sizeof(char[i]))))
933 memcpy(loc->locinfo->lconv->negative_sign, buf, sizeof(char[i]));
935 MSVCRT__free_locale(loc);
939 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IINTLCURRDIGITS
940 |LOCALE_NOUSEROVERRIDE, buf, 256))
941 loc->locinfo->lconv->int_frac_digits = atoi(buf);
943 MSVCRT__free_locale(loc);
947 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_ICURRDIGITS
948 |LOCALE_NOUSEROVERRIDE, buf, 256))
949 loc->locinfo->lconv->frac_digits = atoi(buf);
951 MSVCRT__free_locale(loc);
955 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSYMPRECEDES
956 |LOCALE_NOUSEROVERRIDE, buf, 256))
957 loc->locinfo->lconv->p_cs_precedes = atoi(buf);
959 MSVCRT__free_locale(loc);
963 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSEPBYSPACE
964 |LOCALE_NOUSEROVERRIDE, buf, 256))
965 loc->locinfo->lconv->p_sep_by_space = atoi(buf);
967 MSVCRT__free_locale(loc);
971 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSYMPRECEDES
972 |LOCALE_NOUSEROVERRIDE, buf, 256))
973 loc->locinfo->lconv->n_cs_precedes = atoi(buf);
975 MSVCRT__free_locale(loc);
979 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSEPBYSPACE
980 |LOCALE_NOUSEROVERRIDE, buf, 256))
981 loc->locinfo->lconv->n_sep_by_space = atoi(buf);
983 MSVCRT__free_locale(loc);
987 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSIGNPOSN
988 |LOCALE_NOUSEROVERRIDE, buf, 256))
989 loc->locinfo->lconv->p_sign_posn = atoi(buf);
991 MSVCRT__free_locale(loc);
995 if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSIGNPOSN
996 |LOCALE_NOUSEROVERRIDE, buf, 256))
997 loc->locinfo->lconv->n_sign_posn = atoi(buf);
999 MSVCRT__free_locale(loc);
1003 loc->locinfo->lconv->int_curr_symbol = MSVCRT_malloc(sizeof(char));
1004 loc->locinfo->lconv->currency_symbol = MSVCRT_malloc(sizeof(char));
1005 loc->locinfo->lconv->mon_decimal_point = MSVCRT_malloc(sizeof(char));
1006 loc->locinfo->lconv->mon_thousands_sep = MSVCRT_malloc(sizeof(char));
1007 loc->locinfo->lconv->mon_grouping = MSVCRT_malloc(sizeof(char));
1008 loc->locinfo->lconv->positive_sign = MSVCRT_malloc(sizeof(char));
1009 loc->locinfo->lconv->negative_sign = MSVCRT_malloc(sizeof(char));
1011 if(!loc->locinfo->lconv->int_curr_symbol || !loc->locinfo->lconv->currency_symbol
1012 || !loc->locinfo->lconv->mon_decimal_point || !loc->locinfo->lconv->mon_thousands_sep
1013 || !loc->locinfo->lconv->mon_grouping || !loc->locinfo->lconv->positive_sign
1014 || !loc->locinfo->lconv->negative_sign) {
1015 MSVCRT__free_locale(loc);
1019 loc->locinfo->lconv->int_curr_symbol[0] = '\0';
1020 loc->locinfo->lconv->currency_symbol[0] = '\0';
1021 loc->locinfo->lconv->mon_decimal_point[0] = '\0';
1022 loc->locinfo->lconv->mon_thousands_sep[0] = '\0';
1023 loc->locinfo->lconv->mon_grouping[0] = '\0';
1024 loc->locinfo->lconv->positive_sign[0] = '\0';
1025 loc->locinfo->lconv->negative_sign[0] = '\0';
1026 loc->locinfo->lconv->int_frac_digits = 127;
1027 loc->locinfo->lconv->frac_digits = 127;
1028 loc->locinfo->lconv->p_cs_precedes = 127;
1029 loc->locinfo->lconv->p_sep_by_space = 127;
1030 loc->locinfo->lconv->n_cs_precedes = 127;
1031 loc->locinfo->lconv->n_sep_by_space = 127;
1032 loc->locinfo->lconv->p_sign_posn = 127;
1033 loc->locinfo->lconv->n_sign_posn = 127;
1035 loc->locinfo->lc_category[MSVCRT_LC_MONETARY].locale = MSVCRT__strdup("C");
1038 if(lcid[MSVCRT_LC_NUMERIC] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_NUMERIC)) {
1039 if(update_threadlocinfo_category(lcid[MSVCRT_LC_NUMERIC], loc, MSVCRT_LC_NUMERIC)) {
1040 MSVCRT__free_locale(loc);
1044 if(!loc->locinfo->lconv_intl_refcount)
1045 loc->locinfo->lconv_intl_refcount = MSVCRT_malloc(sizeof(int));
1046 loc->locinfo->lconv_num_refcount = MSVCRT_malloc(sizeof(int));
1047 if(!loc->locinfo->lconv_intl_refcount || !loc->locinfo->lconv_num_refcount) {
1048 MSVCRT__free_locale(loc);
1052 *loc->locinfo->lconv_intl_refcount = 1;
1053 *loc->locinfo->lconv_num_refcount = 1;
1055 i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_SDECIMAL
1056 |LOCALE_NOUSEROVERRIDE, buf, 256);
1057 if(i && (loc->locinfo->lconv->decimal_point = MSVCRT_malloc(sizeof(char[i]))))
1058 memcpy(loc->locinfo->lconv->decimal_point, buf, sizeof(char[i]));
1060 MSVCRT__free_locale(loc);
1064 i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_STHOUSAND
1065 |LOCALE_NOUSEROVERRIDE, buf, 256);
1066 if(i && (loc->locinfo->lconv->thousands_sep = MSVCRT_malloc(sizeof(char[i]))))
1067 memcpy(loc->locinfo->lconv->thousands_sep, buf, sizeof(char[i]));
1069 MSVCRT__free_locale(loc);
1073 i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_SGROUPING
1074 |LOCALE_NOUSEROVERRIDE, buf, 256);
1076 i = i/2 + (buf[i-2]=='0'?0:1);
1077 if(i && (loc->locinfo->lconv->grouping = MSVCRT_malloc(sizeof(char[i])))) {
1078 for(i=0; buf[i+1]==';'; i+=2)
1079 loc->locinfo->lconv->grouping[i/2] = buf[i]-'0';
1080 loc->locinfo->lconv->grouping[i/2] = buf[i]-'0';
1082 loc->locinfo->lconv->grouping[i/2+1] = 127;
1084 MSVCRT__free_locale(loc);
1088 loc->locinfo->lconv->decimal_point = MSVCRT_malloc(sizeof(char[2]));
1089 loc->locinfo->lconv->thousands_sep = MSVCRT_malloc(sizeof(char));
1090 loc->locinfo->lconv->grouping = MSVCRT_malloc(sizeof(char));
1091 if(!loc->locinfo->lconv->decimal_point || !loc->locinfo->lconv->thousands_sep
1092 || !loc->locinfo->lconv->grouping) {
1093 MSVCRT__free_locale(loc);
1097 loc->locinfo->lconv->decimal_point[0] = '.';
1098 loc->locinfo->lconv->decimal_point[1] = '\0';
1099 loc->locinfo->lconv->thousands_sep[0] = '\0';
1100 loc->locinfo->lconv->grouping[0] = '\0';
1102 loc->locinfo->lc_category[MSVCRT_LC_NUMERIC].locale = MSVCRT__strdup("C");
1105 if(lcid[MSVCRT_LC_TIME] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_TIME)) {
1106 if(update_threadlocinfo_category(lcid[MSVCRT_LC_TIME], loc, MSVCRT_LC_TIME)) {
1107 MSVCRT__free_locale(loc);
1111 loc->locinfo->lc_category[MSVCRT_LC_TIME].locale = MSVCRT__strdup("C");
1116 /*********************************************************************
1117 * setlocale (MSVCRT.@)
1119 char* CDECL MSVCRT_setlocale(int category, const char* locale)
1121 MSVCRT__locale_t loc;
1122 MSVCRT_pthreadlocinfo locinfo = get_locinfo();
1124 if(category<MSVCRT_LC_MIN || category>MSVCRT_LC_MAX)
1128 if(category == MSVCRT_LC_ALL)
1129 return construct_lc_all(locinfo);
1131 return locinfo->lc_category[category].locale;
1134 loc = MSVCRT__create_locale(category, locale);
1136 WARN("%d %s failed\n", category, locale);
1144 case MSVCRT_LC_COLLATE:
1145 locinfo->lc_handle[MSVCRT_LC_COLLATE] =
1146 loc->locinfo->lc_handle[MSVCRT_LC_COLLATE];
1147 swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_COLLATE].locale,
1148 (void**)&loc->locinfo->lc_category[MSVCRT_LC_COLLATE].locale);
1149 swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_COLLATE].refcount,
1150 (void**)&loc->locinfo->lc_category[MSVCRT_LC_COLLATE].refcount);
1152 if(category != MSVCRT_LC_ALL)
1154 case MSVCRT_LC_CTYPE:
1155 locinfo->lc_handle[MSVCRT_LC_CTYPE] =
1156 loc->locinfo->lc_handle[MSVCRT_LC_CTYPE];
1157 swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_CTYPE].locale,
1158 (void**)&loc->locinfo->lc_category[MSVCRT_LC_CTYPE].locale);
1159 swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_CTYPE].refcount,
1160 (void**)&loc->locinfo->lc_category[MSVCRT_LC_CTYPE].refcount);
1162 locinfo->lc_codepage = loc->locinfo->lc_codepage;
1163 locinfo->lc_collate_cp = loc->locinfo->lc_collate_cp;
1164 locinfo->lc_clike = loc->locinfo->lc_clike;
1165 locinfo->mb_cur_max = loc->locinfo->mb_cur_max;
1167 swap_pointers((void**)&locinfo->ctype1_refcount,
1168 (void**)&loc->locinfo->ctype1_refcount);
1169 swap_pointers((void**)&locinfo->ctype1, (void**)&loc->locinfo->ctype1);
1170 swap_pointers((void**)&locinfo->pctype, (void**)&loc->locinfo->pctype);
1171 swap_pointers((void**)&locinfo->pclmap, (void**)&loc->locinfo->pclmap);
1172 swap_pointers((void**)&locinfo->pcumap, (void**)&loc->locinfo->pcumap);
1174 memcpy(get_mbcinfo(), loc->mbcinfo, sizeof(MSVCRT_threadmbcinfo));
1176 if(category != MSVCRT_LC_ALL)
1178 case MSVCRT_LC_MONETARY:
1179 locinfo->lc_handle[MSVCRT_LC_MONETARY] =
1180 loc->locinfo->lc_handle[MSVCRT_LC_MONETARY];
1181 swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_MONETARY].locale,
1182 (void**)&loc->locinfo->lc_category[MSVCRT_LC_MONETARY].locale);
1183 swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_MONETARY].refcount,
1184 (void**)&loc->locinfo->lc_category[MSVCRT_LC_MONETARY].refcount);
1186 swap_pointers((void**)&locinfo->lconv->int_curr_symbol,
1187 (void**)&loc->locinfo->lconv->int_curr_symbol);
1188 swap_pointers((void**)&locinfo->lconv->currency_symbol,
1189 (void**)&loc->locinfo->lconv->currency_symbol);
1190 swap_pointers((void**)&locinfo->lconv->mon_decimal_point,
1191 (void**)&loc->locinfo->lconv->mon_decimal_point);
1192 swap_pointers((void**)&locinfo->lconv->mon_thousands_sep,
1193 (void**)&loc->locinfo->lconv->mon_thousands_sep);
1194 swap_pointers((void**)&locinfo->lconv->mon_grouping,
1195 (void**)&loc->locinfo->lconv->mon_grouping);
1196 swap_pointers((void**)&locinfo->lconv->positive_sign,
1197 (void**)&loc->locinfo->lconv->positive_sign);
1198 swap_pointers((void**)&locinfo->lconv->negative_sign,
1199 (void**)&loc->locinfo->lconv->negative_sign);
1200 locinfo->lconv->int_frac_digits = loc->locinfo->lconv->int_frac_digits;
1201 locinfo->lconv->frac_digits = loc->locinfo->lconv->frac_digits;
1202 locinfo->lconv->p_cs_precedes = loc->locinfo->lconv->p_cs_precedes;
1203 locinfo->lconv->p_sep_by_space = loc->locinfo->lconv->p_sep_by_space;
1204 locinfo->lconv->n_cs_precedes = loc->locinfo->lconv->n_cs_precedes;
1205 locinfo->lconv->n_sep_by_space = loc->locinfo->lconv->n_sep_by_space;
1206 locinfo->lconv->p_sign_posn = loc->locinfo->lconv->p_sign_posn;
1207 locinfo->lconv->n_sign_posn = loc->locinfo->lconv->n_sign_posn;
1209 if(category != MSVCRT_LC_ALL)
1211 case MSVCRT_LC_NUMERIC:
1212 locinfo->lc_handle[MSVCRT_LC_NUMERIC] =
1213 loc->locinfo->lc_handle[MSVCRT_LC_NUMERIC];
1214 swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_NUMERIC].locale,
1215 (void**)&loc->locinfo->lc_category[MSVCRT_LC_NUMERIC].locale);
1216 swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_NUMERIC].refcount,
1217 (void**)&loc->locinfo->lc_category[MSVCRT_LC_NUMERIC].refcount);
1219 swap_pointers((void**)&locinfo->lconv->decimal_point,
1220 (void**)&loc->locinfo->lconv->decimal_point);
1221 swap_pointers((void**)&locinfo->lconv->thousands_sep,
1222 (void**)&loc->locinfo->lconv->thousands_sep);
1223 swap_pointers((void**)&locinfo->lconv->grouping,
1224 (void**)&loc->locinfo->lconv->grouping);
1226 if(category != MSVCRT_LC_ALL)
1228 case MSVCRT_LC_TIME:
1229 locinfo->lc_handle[MSVCRT_LC_TIME] =
1230 loc->locinfo->lc_handle[MSVCRT_LC_TIME];
1231 swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_TIME].locale,
1232 (void**)&loc->locinfo->lc_category[MSVCRT_LC_TIME].locale);
1233 swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_TIME].refcount,
1234 (void**)&loc->locinfo->lc_category[MSVCRT_LC_TIME].refcount);
1236 if(category != MSVCRT_LC_ALL)
1240 MSVCRT__free_locale(loc);
1243 if(locinfo == MSVCRT_locale->locinfo) {
1246 MSVCRT___lc_codepage = locinfo->lc_codepage;
1247 MSVCRT___lc_collate_cp = locinfo->lc_collate_cp;
1248 MSVCRT___mb_cur_max = locinfo->mb_cur_max;
1249 MSVCRT__pctype = locinfo->pctype;
1250 for(i=MSVCRT_LC_MIN; i<=MSVCRT_LC_MAX; i++)
1251 MSVCRT___lc_handle[i] = MSVCRT_locale->locinfo->lc_handle[i];
1254 if(category == MSVCRT_LC_ALL)
1255 return construct_lc_all(locinfo);
1257 return locinfo->lc_category[category].locale;
1260 /* _configthreadlocale - not exported in native msvcrt */
1261 int CDECL _configthreadlocale(int type)
1263 thread_data_t *data = msvcrt_get_thread_data();
1264 MSVCRT__locale_t locale;
1270 ret = (data->have_locale ? MSVCRT__ENABLE_PER_THREAD_LOCALE : MSVCRT__DISABLE_PER_THREAD_LOCALE);
1272 if(type == MSVCRT__ENABLE_PER_THREAD_LOCALE) {
1273 if(!data->have_locale) {
1274 /* Copy current global locale */
1275 locale = MSVCRT__create_locale(MSVCRT_LC_ALL, MSVCRT_setlocale(MSVCRT_LC_ALL, NULL));
1279 data->locinfo = locale->locinfo;
1280 data->mbcinfo = locale->mbcinfo;
1281 data->have_locale = TRUE;
1282 MSVCRT_free(locale);
1288 if(type == MSVCRT__DISABLE_PER_THREAD_LOCALE) {
1289 if(data->have_locale) {
1290 free_locinfo(data->locinfo);
1291 free_mbcinfo(data->mbcinfo);
1292 data->locinfo = MSVCRT_locale->locinfo;
1293 data->mbcinfo = MSVCRT_locale->mbcinfo;
1294 data->have_locale = FALSE;
1306 BOOL msvcrt_init_locale(void)
1311 MSVCRT_locale = MSVCRT__create_locale(0, "C");
1316 MSVCRT___lc_codepage = MSVCRT_locale->locinfo->lc_codepage;
1317 MSVCRT___lc_collate_cp = MSVCRT_locale->locinfo->lc_collate_cp;
1318 MSVCRT___mb_cur_max = MSVCRT_locale->locinfo->mb_cur_max;
1319 MSVCRT__pctype = MSVCRT_locale->locinfo->pctype;
1320 for(i=MSVCRT_LC_MIN; i<=MSVCRT_LC_MAX; i++)
1321 MSVCRT___lc_handle[i] = MSVCRT_locale->locinfo->lc_handle[i];