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 unsigned short *MSVCRT__pctype
= NULL
;
45 unsigned int MSVCRT___lc_codepage
= 0;
46 int MSVCRT___lc_collate_cp
= 0;
47 LCID MSVCRT___lc_handle
[MSVCRT_LC_MAX
- MSVCRT_LC_MIN
+ 1] = { 0 };
48 int MSVCRT___mb_cur_max
= 1;
49 static unsigned char charmax
= CHAR_MAX
;
52 #define LOCK_LOCALE _mlock(_SETLOCALE_LOCK);
53 #define UNLOCK_LOCALE _munlock(_SETLOCALE_LOCK);
55 #define MSVCRT_LEADBYTE 0x8000
56 #define MSVCRT_C1_DEFINED 0x200
58 /* Friendly country strings & language names abbreviations. */
59 static const char * const _country_synonyms
[] =
62 "american english", "enu",
63 "american-english", "enu",
64 "english-american", "enu",
72 "french-belgian", "frb",
75 "french-canadian", "frc",
77 "chinese-simplified", "chs",
78 "chinese-traditional", "cht",
79 "dutch-belgian", "nlb",
83 "french-swiss", "frs",
85 "german-swiss", "des",
86 "italian-swiss", "its",
87 "german-austrian", "dea",
89 "portuguese-brazil", "ptb",
90 "spanish-mexican", "esm",
91 "norwegian-bokmal", "nor",
92 "norwegian-nynorsk", "non",
93 "spanish-modern", "esn"
96 /* INTERNAL: Map a synonym to an ISO code */
97 static void remap_synonym(char *name
)
100 for (i
= 0; i
< sizeof(_country_synonyms
)/sizeof(char*); i
+= 2 )
102 if (!strcasecmp(_country_synonyms
[i
],name
))
104 TRACE(":Mapping synonym %s to %s\n",name
,_country_synonyms
[i
+1]);
105 strcpy(name
, _country_synonyms
[i
+1]);
111 /* Note: Flags are weighted in order of matching importance */
112 #define FOUND_LANGUAGE 0x4
113 #define FOUND_COUNTRY 0x2
114 #define FOUND_CODEPAGE 0x1
117 char search_language
[MAX_ELEM_LEN
];
118 char search_country
[MAX_ELEM_LEN
];
119 char search_codepage
[MAX_ELEM_LEN
];
120 char found_codepage
[MAX_ELEM_LEN
];
121 unsigned int match_flags
;
122 LANGID found_lang_id
;
125 #define CONTINUE_LOOKING TRUE
126 #define STOP_LOOKING FALSE
128 /* INTERNAL: Get and compare locale info with a given string */
129 static int compare_info(LCID lcid
, DWORD flags
, char* buff
, const char* cmp
, BOOL exact
)
137 GetLocaleInfoA(lcid
, flags
|LOCALE_NOUSEROVERRIDE
, buff
, MAX_ELEM_LEN
);
141 /* Partial matches are only allowed on language/country names */
144 return !strcasecmp(cmp
, buff
);
146 return !strncasecmp(cmp
, buff
, len
);
150 find_best_locale_proc(HMODULE hModule
, LPCSTR type
, LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
152 locale_search_t
*res
= (locale_search_t
*)lParam
;
153 const LCID lcid
= MAKELCID(LangID
, SORT_DEFAULT
);
154 char buff
[MAX_ELEM_LEN
];
155 unsigned int flags
= 0;
157 if(PRIMARYLANGID(LangID
) == LANG_NEUTRAL
)
158 return CONTINUE_LOOKING
;
161 if (compare_info(lcid
,LOCALE_SISO639LANGNAME
,buff
,res
->search_language
, TRUE
) ||
162 compare_info(lcid
,LOCALE_SABBREVLANGNAME
,buff
,res
->search_language
, TRUE
) ||
163 compare_info(lcid
,LOCALE_SENGLANGUAGE
,buff
,res
->search_language
, FALSE
))
165 TRACE(":Found language: %s->%s\n", res
->search_language
, buff
);
166 flags
|= FOUND_LANGUAGE
;
168 else if (res
->match_flags
& FOUND_LANGUAGE
)
170 return CONTINUE_LOOKING
;
174 if (compare_info(lcid
,LOCALE_SISO3166CTRYNAME
,buff
,res
->search_country
, TRUE
) ||
175 compare_info(lcid
,LOCALE_SABBREVCTRYNAME
,buff
,res
->search_country
, TRUE
) ||
176 compare_info(lcid
,LOCALE_SENGCOUNTRY
,buff
,res
->search_country
, FALSE
))
178 TRACE("Found country:%s->%s\n", res
->search_country
, buff
);
179 flags
|= FOUND_COUNTRY
;
181 else if (!flags
&& (res
->match_flags
& FOUND_COUNTRY
))
183 return CONTINUE_LOOKING
;
187 if (compare_info(lcid
,LOCALE_IDEFAULTCODEPAGE
,buff
,res
->search_codepage
, TRUE
) ||
188 (compare_info(lcid
,LOCALE_IDEFAULTANSICODEPAGE
,buff
,res
->search_codepage
, TRUE
)))
190 TRACE("Found codepage:%s->%s\n", res
->search_codepage
, buff
);
191 flags
|= FOUND_CODEPAGE
;
192 memcpy(res
->found_codepage
,res
->search_codepage
,MAX_ELEM_LEN
);
194 else if (!flags
&& (res
->match_flags
& FOUND_CODEPAGE
))
196 return CONTINUE_LOOKING
;
199 if (flags
> res
->match_flags
)
201 /* Found a better match than previously */
202 res
->match_flags
= flags
;
203 res
->found_lang_id
= LangID
;
205 if ((flags
& (FOUND_LANGUAGE
| FOUND_COUNTRY
| FOUND_CODEPAGE
)) ==
206 (FOUND_LANGUAGE
| FOUND_COUNTRY
| FOUND_CODEPAGE
))
208 TRACE(":found exact locale match\n");
211 return CONTINUE_LOOKING
;
214 extern int atoi(const char *);
216 /* Internal: Find the LCID for a locale specification */
217 LCID
MSVCRT_locale_to_LCID(const char *locale
, unsigned short *codepage
)
220 locale_search_t search
;
221 const char *cp
, *region
;
223 memset(&search
, 0, sizeof(locale_search_t
));
225 cp
= strchr(locale
, '.');
226 region
= strchr(locale
, '_');
228 lstrcpynA(search
.search_language
, locale
, MAX_ELEM_LEN
);
230 lstrcpynA(search
.search_country
, region
+1, MAX_ELEM_LEN
);
231 if(region
-locale
< MAX_ELEM_LEN
)
232 search
.search_language
[region
-locale
] = '\0';
234 search
.search_country
[0] = '\0';
237 lstrcpynA(search
.search_codepage
, cp
+1, MAX_ELEM_LEN
);
238 if(region
&& cp
-region
-1<MAX_ELEM_LEN
)
239 search
.search_country
[cp
-region
-1] = '\0';
240 if(cp
-locale
< MAX_ELEM_LEN
)
241 search
.search_language
[cp
-locale
] = '\0';
243 search
.search_codepage
[0] = '\0';
245 if(!search
.search_country
[0] && !search
.search_codepage
[0])
246 remap_synonym(search
.search_language
);
248 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), (LPSTR
)RT_STRING
,
249 (LPCSTR
)LOCALE_ILANGUAGE
,find_best_locale_proc
,
252 if (!search
.match_flags
)
255 /* If we were given something that didn't match, fail */
256 if (search
.search_country
[0] && !(search
.match_flags
& FOUND_COUNTRY
))
259 lcid
= MAKELCID(search
.found_lang_id
, SORT_DEFAULT
);
261 /* Populate partial locale, translating LCID to locale string elements */
262 if (!(search
.match_flags
& FOUND_CODEPAGE
)) {
263 /* Even if a codepage is not enumerated for a locale
264 * it can be set if valid */
265 if (search
.search_codepage
[0]) {
266 if (IsValidCodePage(atoi(search
.search_codepage
)))
267 memcpy(search
.found_codepage
,search
.search_codepage
,MAX_ELEM_LEN
);
269 /* Special codepage values: OEM & ANSI */
270 if (!strcasecmp(search
.search_codepage
,"OCP")) {
271 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTCODEPAGE
,
272 search
.found_codepage
, MAX_ELEM_LEN
);
273 } else if (!strcasecmp(search
.search_codepage
,"ACP")) {
274 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
,
275 search
.found_codepage
, MAX_ELEM_LEN
);
279 if (!atoi(search
.found_codepage
))
283 /* Prefer ANSI codepages if present */
284 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
,
285 search
.found_codepage
, MAX_ELEM_LEN
);
286 if (!search
.found_codepage
[0] || !atoi(search
.found_codepage
))
287 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTCODEPAGE
,
288 search
.found_codepage
, MAX_ELEM_LEN
);
292 *codepage
= atoi(search
.found_codepage
);
297 /* INTERNAL: Set lc_handle, lc_id and lc_category in threadlocinfo struct */
298 static BOOL
update_threadlocinfo_category(LCID lcid
, unsigned short cp
,
299 MSVCRT__locale_t loc
, int category
)
304 if(GetLocaleInfoA(lcid
, LOCALE_ILANGUAGE
|LOCALE_NOUSEROVERRIDE
, buf
, 256)) {
307 loc
->locinfo
->lc_id
[category
].wLanguage
= 0;
309 loc
->locinfo
->lc_id
[category
].wLanguage
*= 16;
312 loc
->locinfo
->lc_id
[category
].wLanguage
+= *p
-'0';
314 loc
->locinfo
->lc_id
[category
].wLanguage
+= *p
-'a'+10;
319 loc
->locinfo
->lc_id
[category
].wCountry
=
320 loc
->locinfo
->lc_id
[category
].wLanguage
;
323 loc
->locinfo
->lc_id
[category
].wCodePage
= cp
;
325 loc
->locinfo
->lc_handle
[category
] = lcid
;
328 len
+= GetLocaleInfoA(lcid
, LOCALE_SENGLANGUAGE
329 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
331 len
+= GetLocaleInfoA(lcid
, LOCALE_SENGCOUNTRY
332 |LOCALE_NOUSEROVERRIDE
, &buf
[len
], 256-len
);
334 sprintf(buf
+len
, "%d", cp
);
335 len
+= strlen(buf
+len
)+1;
337 loc
->locinfo
->lc_category
[category
].locale
= MSVCRT_malloc(len
);
338 loc
->locinfo
->lc_category
[category
].refcount
= MSVCRT_malloc(sizeof(int));
339 if(!loc
->locinfo
->lc_category
[category
].locale
340 || !loc
->locinfo
->lc_category
[category
].refcount
) {
341 MSVCRT_free(loc
->locinfo
->lc_category
[category
].locale
);
342 MSVCRT_free(loc
->locinfo
->lc_category
[category
].refcount
);
343 loc
->locinfo
->lc_category
[category
].locale
= NULL
;
344 loc
->locinfo
->lc_category
[category
].refcount
= NULL
;
347 memcpy(loc
->locinfo
->lc_category
[category
].locale
, buf
, len
);
348 *loc
->locinfo
->lc_category
[category
].refcount
= 1;
353 /* INTERNAL: swap pointers values */
354 static inline void swap_pointers(void **p1
, void **p2
) {
362 /* INTERNAL: returns pthreadlocinfo struct */
363 MSVCRT_pthreadlocinfo
get_locinfo(void) {
364 thread_data_t
*data
= msvcrt_get_thread_data();
366 if(!data
|| !data
->have_locale
)
367 return MSVCRT_locale
->locinfo
;
369 return data
->locinfo
;
372 /* INTERNAL: returns pthreadlocinfo struct */
373 MSVCRT_pthreadmbcinfo
get_mbcinfo(void) {
374 thread_data_t
*data
= msvcrt_get_thread_data();
376 if(!data
|| !data
->have_locale
)
377 return MSVCRT_locale
->mbcinfo
;
379 return data
->mbcinfo
;
382 /* INTERNAL: constructs string returned by setlocale */
383 static inline char* construct_lc_all(MSVCRT_pthreadlocinfo locinfo
) {
384 static char current_lc_all
[MAX_LOCALE_LENGTH
];
388 for(i
=MSVCRT_LC_MIN
+1; i
<MSVCRT_LC_MAX
; i
++) {
389 if(strcmp(locinfo
->lc_category
[i
].locale
,
390 locinfo
->lc_category
[i
+1].locale
))
395 return locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
;
397 sprintf(current_lc_all
,
398 "LC_COLLATE=%s;LC_CTYPE=%s;LC_MONETARY=%s;LC_NUMERIC=%s;LC_TIME=%s",
399 locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
,
400 locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
,
401 locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
,
402 locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
,
403 locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
);
405 return current_lc_all
;
409 /*********************************************************************
410 * _Getdays (MSVCRT.@)
412 char* CDECL
_Getdays(void)
414 MSVCRT___lc_time_data
*cur
= get_locinfo()->lc_time_curr
;
420 size
= cur
->str
.names
.short_mon
[0]-cur
->str
.names
.short_wday
[0];
421 out
= MSVCRT_malloc(size
+1);
428 len
= strlen(cur
->str
.names
.short_wday
[i
]);
429 memcpy(&out
[size
], cur
->str
.names
.short_wday
[i
], len
);
433 len
= strlen(cur
->str
.names
.wday
[i
]);
434 memcpy(&out
[size
], cur
->str
.names
.wday
[i
], len
);
442 /*********************************************************************
443 * _Getmonths (MSVCRT.@)
445 char* CDECL
_Getmonths(void)
447 MSVCRT___lc_time_data
*cur
= get_locinfo()->lc_time_curr
;
453 size
= cur
->str
.names
.am
-cur
->str
.names
.short_mon
[0];
454 out
= MSVCRT_malloc(size
+1);
459 for(i
=0; i
<12; i
++) {
461 len
= strlen(cur
->str
.names
.short_mon
[i
]);
462 memcpy(&out
[size
], cur
->str
.names
.short_mon
[i
], len
);
466 len
= strlen(cur
->str
.names
.mon
[i
]);
467 memcpy(&out
[size
], cur
->str
.names
.mon
[i
], len
);
475 /*********************************************************************
476 * _Gettnames (MSVCRT.@)
478 void* CDECL
_Gettnames(void)
480 MSVCRT___lc_time_data
*ret
, *cur
= get_locinfo()->lc_time_curr
;
481 unsigned int i
, size
= sizeof(MSVCRT___lc_time_data
);
485 for(i
=0; i
<sizeof(cur
->str
.str
)/sizeof(cur
->str
.str
[0]); i
++)
486 size
+= strlen(cur
->str
.str
[i
])+1;
488 ret
= MSVCRT_malloc(size
);
491 memcpy(ret
, cur
, size
);
494 for(i
=0; i
<sizeof(cur
->str
.str
)/sizeof(cur
->str
.str
[0]); i
++) {
495 ret
->str
.str
[i
] = &ret
->data
[size
];
496 size
+= strlen(&ret
->data
[size
])+1;
502 /*********************************************************************
503 * __crtLCMapStringA (MSVCRT.@)
505 int CDECL
__crtLCMapStringA(
506 LCID lcid
, DWORD mapflags
, const char* src
, int srclen
, char* dst
,
507 int dstlen
, unsigned int codepage
, int xflag
509 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
510 lcid
,mapflags
,src
,srclen
,dst
,dstlen
,codepage
,xflag
);
511 /* FIXME: A bit incorrect. But msvcrt itself just converts its
512 * arguments to wide strings and then calls LCMapStringW
514 return LCMapStringA(lcid
,mapflags
,src
,srclen
,dst
,dstlen
);
517 /*********************************************************************
518 * __crtLCMapStringW (MSVCRT.@)
520 int CDECL
__crtLCMapStringW(LCID lcid
, DWORD mapflags
, const MSVCRT_wchar_t
*src
,
521 int srclen
, MSVCRT_wchar_t
*dst
, int dstlen
, unsigned int codepage
, int xflag
)
523 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
524 lcid
, mapflags
, debugstr_w(src
), srclen
, dst
, dstlen
, codepage
, xflag
);
526 return LCMapStringW(lcid
, mapflags
, src
, srclen
, dst
, dstlen
);
529 /*********************************************************************
530 * __crtCompareStringA (MSVCRT.@)
532 int CDECL
__crtCompareStringA( LCID lcid
, DWORD flags
, const char *src1
, int len1
,
533 const char *src2
, int len2
)
535 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
536 lcid
, flags
, debugstr_a(src1
), len1
, debugstr_a(src2
), len2
);
537 /* FIXME: probably not entirely right */
538 return CompareStringA( lcid
, flags
, src1
, len1
, src2
, len2
);
541 /*********************************************************************
542 * __crtCompareStringW (MSVCRT.@)
544 int CDECL
__crtCompareStringW( LCID lcid
, DWORD flags
, const MSVCRT_wchar_t
*src1
, int len1
,
545 const MSVCRT_wchar_t
*src2
, int len2
)
547 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
548 lcid
, flags
, debugstr_w(src1
), len1
, debugstr_w(src2
), len2
);
549 /* FIXME: probably not entirely right */
550 return CompareStringW( lcid
, flags
, src1
, len1
, src2
, len2
);
553 /*********************************************************************
554 * __crtGetLocaleInfoW (MSVCRT.@)
556 int CDECL
__crtGetLocaleInfoW( LCID lcid
, LCTYPE type
, MSVCRT_wchar_t
*buffer
, int len
)
558 FIXME("(lcid %x, type %x, %p(%d), partial stub\n", lcid
, type
, buffer
, len
);
559 /* FIXME: probably not entirely right */
560 return GetLocaleInfoW( lcid
, type
, buffer
, len
);
563 /*********************************************************************
566 MSVCRT_wint_t CDECL
MSVCRT_btowc(int c
)
568 unsigned char letter
= c
;
571 if(!MultiByteToWideChar(get_locinfo()->lc_handle
[MSVCRT_LC_CTYPE
],
572 0, (LPCSTR
)&letter
, 1, &ret
, 1))
578 /*********************************************************************
579 * __crtGetStringTypeW(MSVCRT.@)
581 * This function was accepting different number of arguments in older
582 * versions of msvcrt.
584 BOOL CDECL
__crtGetStringTypeW(DWORD unk
, DWORD type
,
585 MSVCRT_wchar_t
*buffer
, int len
, WORD
*out
)
587 FIXME("(unk %x, type %x, wstr %p(%d), %p) partial stub\n",
588 unk
, type
, buffer
, len
, out
);
590 return GetStringTypeW(type
, buffer
, len
, out
);
593 /*********************************************************************
594 * localeconv (MSVCRT.@)
596 struct MSVCRT_lconv
* CDECL
MSVCRT_localeconv(void)
598 return get_locinfo()->lconv
;
601 /*********************************************************************
602 * __lconv_init (MSVCRT.@)
604 int CDECL
__lconv_init(void)
606 /* this is used to make chars unsigned */
611 /*********************************************************************
612 * ___lc_handle_func (MSVCRT.@)
614 LCID
* CDECL
___lc_handle_func(void)
616 return get_locinfo()->lc_handle
;
619 /*********************************************************************
620 * ___lc_codepage_func (MSVCRT.@)
622 unsigned int CDECL
___lc_codepage_func(void)
624 return get_locinfo()->lc_codepage
;
627 /*********************************************************************
628 * ___lc_collate_cp_func (MSVCRT.@)
630 int CDECL
___lc_collate_cp_func(void)
632 return get_locinfo()->lc_collate_cp
;
635 /* INTERNAL: frees MSVCRT_pthreadlocinfo struct */
636 void free_locinfo(MSVCRT_pthreadlocinfo locinfo
)
643 if(InterlockedDecrement(&locinfo
->refcount
))
646 for(i
=MSVCRT_LC_MIN
+1; i
<=MSVCRT_LC_MAX
; i
++) {
647 MSVCRT_free(locinfo
->lc_category
[i
].locale
);
648 MSVCRT_free(locinfo
->lc_category
[i
].refcount
);
652 MSVCRT_free(locinfo
->lconv
->decimal_point
);
653 MSVCRT_free(locinfo
->lconv
->thousands_sep
);
654 MSVCRT_free(locinfo
->lconv
->grouping
);
655 MSVCRT_free(locinfo
->lconv
->int_curr_symbol
);
656 MSVCRT_free(locinfo
->lconv
->currency_symbol
);
657 MSVCRT_free(locinfo
->lconv
->mon_decimal_point
);
658 MSVCRT_free(locinfo
->lconv
->mon_thousands_sep
);
659 MSVCRT_free(locinfo
->lconv
->mon_grouping
);
660 MSVCRT_free(locinfo
->lconv
->positive_sign
);
661 MSVCRT_free(locinfo
->lconv
->negative_sign
);
662 #if _MSVCR_VER >= 120
663 MSVCRT_free(locinfo
->lconv
->_W_decimal_point
);
664 MSVCRT_free(locinfo
->lconv
->_W_thousands_sep
);
665 MSVCRT_free(locinfo
->lconv
->_W_int_curr_symbol
);
666 MSVCRT_free(locinfo
->lconv
->_W_currency_symbol
);
667 MSVCRT_free(locinfo
->lconv
->_W_mon_decimal_point
);
668 MSVCRT_free(locinfo
->lconv
->_W_mon_thousands_sep
);
669 MSVCRT_free(locinfo
->lconv
->_W_positive_sign
);
670 MSVCRT_free(locinfo
->lconv
->_W_negative_sign
);
673 MSVCRT_free(locinfo
->lconv_intl_refcount
);
674 MSVCRT_free(locinfo
->lconv_num_refcount
);
675 MSVCRT_free(locinfo
->lconv_mon_refcount
);
676 MSVCRT_free(locinfo
->lconv
);
678 MSVCRT_free(locinfo
->ctype1_refcount
);
679 MSVCRT_free(locinfo
->ctype1
);
681 MSVCRT_free(locinfo
->pclmap
);
682 MSVCRT_free(locinfo
->pcumap
);
684 MSVCRT_free(locinfo
->lc_time_curr
);
686 MSVCRT_free(locinfo
);
689 /* INTERNAL: frees MSVCRT_pthreadmbcinfo struct */
690 void free_mbcinfo(MSVCRT_pthreadmbcinfo mbcinfo
)
695 if(InterlockedDecrement(&mbcinfo
->refcount
))
698 MSVCRT_free(mbcinfo
);
701 /*********************************************************************
702 * _get_current_locale (MSVCRT.@)
704 MSVCRT__locale_t CDECL
MSVCRT__get_current_locale(void)
706 MSVCRT__locale_t loc
= MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct
));
710 loc
->locinfo
= get_locinfo();
711 loc
->mbcinfo
= get_mbcinfo();
712 InterlockedIncrement(&loc
->locinfo
->refcount
);
713 InterlockedIncrement(&loc
->mbcinfo
->refcount
);
717 /*********************************************************************
718 * _free_locale (MSVCRT.@)
720 void CDECL
MSVCRT__free_locale(MSVCRT__locale_t locale
)
725 free_locinfo(locale
->locinfo
);
726 free_mbcinfo(locale
->mbcinfo
);
730 /*********************************************************************
731 * _create_locale (MSVCRT.@)
733 MSVCRT__locale_t CDECL
MSVCRT__create_locale(int category
, const char *locale
)
735 static const DWORD time_data
[] = {
736 LOCALE_SABBREVDAYNAME7
, LOCALE_SABBREVDAYNAME1
, LOCALE_SABBREVDAYNAME2
,
737 LOCALE_SABBREVDAYNAME3
, LOCALE_SABBREVDAYNAME4
, LOCALE_SABBREVDAYNAME5
,
738 LOCALE_SABBREVDAYNAME6
,
739 LOCALE_SDAYNAME7
, LOCALE_SDAYNAME1
, LOCALE_SDAYNAME2
, LOCALE_SDAYNAME3
,
740 LOCALE_SDAYNAME4
, LOCALE_SDAYNAME5
, LOCALE_SDAYNAME6
,
741 LOCALE_SABBREVMONTHNAME1
, LOCALE_SABBREVMONTHNAME2
, LOCALE_SABBREVMONTHNAME3
,
742 LOCALE_SABBREVMONTHNAME4
, LOCALE_SABBREVMONTHNAME5
, LOCALE_SABBREVMONTHNAME6
,
743 LOCALE_SABBREVMONTHNAME7
, LOCALE_SABBREVMONTHNAME8
, LOCALE_SABBREVMONTHNAME9
,
744 LOCALE_SABBREVMONTHNAME10
, LOCALE_SABBREVMONTHNAME11
, LOCALE_SABBREVMONTHNAME12
,
745 LOCALE_SMONTHNAME1
, LOCALE_SMONTHNAME2
, LOCALE_SMONTHNAME3
, LOCALE_SMONTHNAME4
,
746 LOCALE_SMONTHNAME5
, LOCALE_SMONTHNAME6
, LOCALE_SMONTHNAME7
, LOCALE_SMONTHNAME8
,
747 LOCALE_SMONTHNAME9
, LOCALE_SMONTHNAME10
, LOCALE_SMONTHNAME11
, LOCALE_SMONTHNAME12
,
748 LOCALE_S1159
, LOCALE_S2359
,
749 LOCALE_SSHORTDATE
, LOCALE_SLONGDATE
,
752 static const char collate
[] = "COLLATE=";
753 static const char ctype
[] = "CTYPE=";
754 static const char monetary
[] = "MONETARY=";
755 static const char numeric
[] = "NUMERIC=";
756 static const char time
[] = "TIME=";
757 static const char cloc_short_date
[] = "MM/dd/yy";
758 static const MSVCRT_wchar_t cloc_short_dateW
[] = {'M','M','/','d','d','/','y','y',0};
759 static const char cloc_long_date
[] = "dddd, MMMM dd, yyyy";
760 static const MSVCRT_wchar_t cloc_long_dateW
[] = {'d','d','d','d',',',' ','M','M','M','M',' ','d','d',',',' ','y','y','y','y',0};
761 static const char cloc_time
[] = "HH:mm:ss";
762 static const MSVCRT_wchar_t cloc_timeW
[] = {'H','H',':','m','m',':','s','s',0};
764 MSVCRT__locale_t loc
;
765 LCID lcid
[6] = { 0 }, lcid_tmp
;
766 unsigned short cp
[6] = { 0 };
768 #if _MSVCR_VER >= 120
769 MSVCRT_wchar_t wbuf
[256];
773 TRACE("(%d %s)\n", category
, locale
);
775 if(category
<MSVCRT_LC_MIN
|| category
>MSVCRT_LC_MAX
|| !locale
)
778 if(locale
[0]=='C' && !locale
[1]) {
781 } else if(!locale
[0]) {
782 lcid
[0] = GetSystemDefaultLCID();
783 GetLocaleInfoA(lcid
[0], LOCALE_IDEFAULTANSICODEPAGE
784 |LOCALE_NOUSEROVERRIDE
, buf
, sizeof(buf
));
791 } else if (locale
[0] == 'L' && locale
[1] == 'C' && locale
[2] == '_') {
795 locale
+= 3; /* LC_ */
796 if(!memcmp(locale
, collate
, sizeof(collate
)-1)) {
797 i
= MSVCRT_LC_COLLATE
;
798 locale
+= sizeof(collate
)-1;
799 } else if(!memcmp(locale
, ctype
, sizeof(ctype
)-1)) {
801 locale
+= sizeof(ctype
)-1;
802 } else if(!memcmp(locale
, monetary
, sizeof(monetary
)-1)) {
803 i
= MSVCRT_LC_MONETARY
;
804 locale
+= sizeof(monetary
)-1;
805 } else if(!memcmp(locale
, numeric
, sizeof(numeric
)-1)) {
806 i
= MSVCRT_LC_NUMERIC
;
807 locale
+= sizeof(numeric
)-1;
808 } else if(!memcmp(locale
, time
, sizeof(time
)-1)) {
810 locale
+= sizeof(time
)-1;
814 p
= strchr(locale
, ';');
815 if(locale
[0]=='C' && (locale
[1]==';' || locale
[1]=='\0')) {
819 memcpy(buf
, locale
, p
-locale
);
820 buf
[p
-locale
] = '\0';
821 lcid
[i
] = MSVCRT_locale_to_LCID(buf
, &cp
[i
]);
823 lcid
[i
] = MSVCRT_locale_to_LCID(locale
, &cp
[i
]);
828 if(!p
|| *(p
+1)!='L' || *(p
+2)!='C' || *(p
+3)!='_')
834 lcid
[0] = MSVCRT_locale_to_LCID(locale
, &cp
[0]);
844 loc
= MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct
));
848 loc
->locinfo
= MSVCRT_malloc(sizeof(MSVCRT_threadlocinfo
));
854 loc
->mbcinfo
= MSVCRT_malloc(sizeof(MSVCRT_threadmbcinfo
));
856 MSVCRT_free(loc
->locinfo
);
861 memset(loc
->locinfo
, 0, sizeof(MSVCRT_threadlocinfo
));
862 loc
->locinfo
->refcount
= 1;
863 loc
->mbcinfo
->refcount
= 1;
865 loc
->locinfo
->lconv
= MSVCRT_malloc(sizeof(struct MSVCRT_lconv
));
866 if(!loc
->locinfo
->lconv
) {
867 MSVCRT__free_locale(loc
);
870 memset(loc
->locinfo
->lconv
, 0, sizeof(struct MSVCRT_lconv
));
872 loc
->locinfo
->pclmap
= MSVCRT_malloc(sizeof(char[256]));
873 loc
->locinfo
->pcumap
= MSVCRT_malloc(sizeof(char[256]));
874 if(!loc
->locinfo
->pclmap
|| !loc
->locinfo
->pcumap
) {
875 MSVCRT__free_locale(loc
);
879 if(lcid
[MSVCRT_LC_COLLATE
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_COLLATE
)) {
880 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_COLLATE
], cp
[MSVCRT_LC_COLLATE
], loc
, MSVCRT_LC_COLLATE
)) {
881 MSVCRT__free_locale(loc
);
885 loc
->locinfo
->lc_collate_cp
= loc
->locinfo
->lc_id
[MSVCRT_LC_COLLATE
].wCodePage
;
887 loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
= MSVCRT__strdup("C");
889 if(lcid
[MSVCRT_LC_CTYPE
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_CTYPE
)) {
893 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_CTYPE
], cp
[MSVCRT_LC_CTYPE
], loc
, MSVCRT_LC_CTYPE
)) {
894 MSVCRT__free_locale(loc
);
898 loc
->locinfo
->lc_codepage
= loc
->locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
;
899 loc
->locinfo
->lc_clike
= 1;
900 if(!GetCPInfo(loc
->locinfo
->lc_codepage
, &cp_info
)) {
901 MSVCRT__free_locale(loc
);
904 loc
->locinfo
->mb_cur_max
= cp_info
.MaxCharSize
;
906 loc
->locinfo
->ctype1_refcount
= MSVCRT_malloc(sizeof(int));
907 loc
->locinfo
->ctype1
= MSVCRT_malloc(sizeof(short[257]));
908 if(!loc
->locinfo
->ctype1_refcount
|| !loc
->locinfo
->ctype1
) {
909 MSVCRT__free_locale(loc
);
913 *loc
->locinfo
->ctype1_refcount
= 1;
914 loc
->locinfo
->ctype1
[0] = 0;
915 loc
->locinfo
->pctype
= loc
->locinfo
->ctype1
+1;
917 buf
[1] = buf
[2] = '\0';
918 for(i
=1; i
<257; i
++) {
921 /* builtin GetStringTypeA doesn't set output to 0 on invalid input */
922 loc
->locinfo
->ctype1
[i
] = 0;
924 GetStringTypeA(lcid
[MSVCRT_LC_CTYPE
], CT_CTYPE1
, buf
,
925 1, loc
->locinfo
->ctype1
+i
);
928 for(i
=0; cp_info
.LeadByte
[i
+1]!=0; i
+=2)
929 for(j
=cp_info
.LeadByte
[i
]; j
<=cp_info
.LeadByte
[i
+1]; j
++)
930 loc
->locinfo
->ctype1
[j
+1] |= MSVCRT__LEADBYTE
;
932 loc
->locinfo
->lc_clike
= 1;
933 loc
->locinfo
->mb_cur_max
= 1;
934 loc
->locinfo
->pctype
= MSVCRT__ctype
+1;
935 loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
= MSVCRT__strdup("C");
938 for(i
=0; i
<256; i
++) {
939 if(loc
->locinfo
->pctype
[i
] & MSVCRT__LEADBYTE
)
946 if(lcid
[MSVCRT_LC_CTYPE
]) {
947 LCMapStringA(lcid
[MSVCRT_LC_CTYPE
], LCMAP_LOWERCASE
, buf
, 256,
948 (char*)loc
->locinfo
->pclmap
, 256);
949 LCMapStringA(lcid
[MSVCRT_LC_CTYPE
], LCMAP_UPPERCASE
, buf
, 256,
950 (char*)loc
->locinfo
->pcumap
, 256);
952 for(i
=0; i
<256; i
++) {
953 loc
->locinfo
->pclmap
[i
] = (i
>='A' && i
<='Z' ? i
-'A'+'a' : i
);
954 loc
->locinfo
->pcumap
[i
] = (i
>='a' && i
<='z' ? i
-'a'+'A' : i
);
958 _setmbcp_l(loc
->locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
, lcid
[MSVCRT_LC_CTYPE
], loc
->mbcinfo
);
960 if(lcid
[MSVCRT_LC_MONETARY
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_MONETARY
)) {
961 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_MONETARY
], cp
[MSVCRT_LC_MONETARY
], loc
, MSVCRT_LC_MONETARY
)) {
962 MSVCRT__free_locale(loc
);
966 loc
->locinfo
->lconv_intl_refcount
= MSVCRT_malloc(sizeof(int));
967 loc
->locinfo
->lconv_mon_refcount
= MSVCRT_malloc(sizeof(int));
968 if(!loc
->locinfo
->lconv_intl_refcount
|| !loc
->locinfo
->lconv_mon_refcount
) {
969 MSVCRT__free_locale(loc
);
973 *loc
->locinfo
->lconv_intl_refcount
= 1;
974 *loc
->locinfo
->lconv_mon_refcount
= 1;
976 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SINTLSYMBOL
977 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
978 if(i
&& (loc
->locinfo
->lconv
->int_curr_symbol
= MSVCRT_malloc(i
)))
979 memcpy(loc
->locinfo
->lconv
->int_curr_symbol
, buf
, i
);
981 MSVCRT__free_locale(loc
);
985 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SCURRENCY
986 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
987 if(i
&& (loc
->locinfo
->lconv
->currency_symbol
= MSVCRT_malloc(i
)))
988 memcpy(loc
->locinfo
->lconv
->currency_symbol
, buf
, i
);
990 MSVCRT__free_locale(loc
);
994 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONDECIMALSEP
995 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
996 if(i
&& (loc
->locinfo
->lconv
->mon_decimal_point
= MSVCRT_malloc(i
)))
997 memcpy(loc
->locinfo
->lconv
->mon_decimal_point
, buf
, i
);
999 MSVCRT__free_locale(loc
);
1003 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONTHOUSANDSEP
1004 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1005 if(i
&& (loc
->locinfo
->lconv
->mon_thousands_sep
= MSVCRT_malloc(i
)))
1006 memcpy(loc
->locinfo
->lconv
->mon_thousands_sep
, buf
, i
);
1008 MSVCRT__free_locale(loc
);
1012 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONGROUPING
1013 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1015 i
= i
/2 + (buf
[i
-2]=='0'?0:1);
1016 if(i
&& (loc
->locinfo
->lconv
->mon_grouping
= MSVCRT_malloc(i
))) {
1017 for(i
=0; buf
[i
+1]==';'; i
+=2)
1018 loc
->locinfo
->lconv
->mon_grouping
[i
/2] = buf
[i
]-'0';
1019 loc
->locinfo
->lconv
->mon_grouping
[i
/2] = buf
[i
]-'0';
1021 loc
->locinfo
->lconv
->mon_grouping
[i
/2+1] = 127;
1023 MSVCRT__free_locale(loc
);
1027 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SPOSITIVESIGN
1028 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1029 if(i
&& (loc
->locinfo
->lconv
->positive_sign
= MSVCRT_malloc(i
)))
1030 memcpy(loc
->locinfo
->lconv
->positive_sign
, buf
, i
);
1032 MSVCRT__free_locale(loc
);
1036 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SNEGATIVESIGN
1037 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1038 if(i
&& (loc
->locinfo
->lconv
->negative_sign
= MSVCRT_malloc(i
)))
1039 memcpy(loc
->locinfo
->lconv
->negative_sign
, buf
, i
);
1041 MSVCRT__free_locale(loc
);
1045 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IINTLCURRDIGITS
1046 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1047 loc
->locinfo
->lconv
->int_frac_digits
= atoi(buf
);
1049 MSVCRT__free_locale(loc
);
1053 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_ICURRDIGITS
1054 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1055 loc
->locinfo
->lconv
->frac_digits
= atoi(buf
);
1057 MSVCRT__free_locale(loc
);
1061 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSYMPRECEDES
1062 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1063 loc
->locinfo
->lconv
->p_cs_precedes
= atoi(buf
);
1065 MSVCRT__free_locale(loc
);
1069 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSEPBYSPACE
1070 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1071 loc
->locinfo
->lconv
->p_sep_by_space
= atoi(buf
);
1073 MSVCRT__free_locale(loc
);
1077 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSYMPRECEDES
1078 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1079 loc
->locinfo
->lconv
->n_cs_precedes
= atoi(buf
);
1081 MSVCRT__free_locale(loc
);
1085 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSEPBYSPACE
1086 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1087 loc
->locinfo
->lconv
->n_sep_by_space
= atoi(buf
);
1089 MSVCRT__free_locale(loc
);
1093 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSIGNPOSN
1094 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1095 loc
->locinfo
->lconv
->p_sign_posn
= atoi(buf
);
1097 MSVCRT__free_locale(loc
);
1101 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSIGNPOSN
1102 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1103 loc
->locinfo
->lconv
->n_sign_posn
= atoi(buf
);
1105 MSVCRT__free_locale(loc
);
1109 #if _MSVCR_VER >= 120
1110 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SINTLSYMBOL
1111 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1112 if(i
&& (loc
->locinfo
->lconv
->_W_int_curr_symbol
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1113 memcpy(loc
->locinfo
->lconv
->_W_int_curr_symbol
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1115 MSVCRT__free_locale(loc
);
1119 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SCURRENCY
1120 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1121 if(i
&& (loc
->locinfo
->lconv
->_W_currency_symbol
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1122 memcpy(loc
->locinfo
->lconv
->_W_currency_symbol
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1124 MSVCRT__free_locale(loc
);
1128 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONDECIMALSEP
1129 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1130 if(i
&& (loc
->locinfo
->lconv
->_W_mon_decimal_point
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1131 memcpy(loc
->locinfo
->lconv
->_W_mon_decimal_point
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1133 MSVCRT__free_locale(loc
);
1137 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONTHOUSANDSEP
1138 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1139 if(i
&& (loc
->locinfo
->lconv
->_W_mon_thousands_sep
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1140 memcpy(loc
->locinfo
->lconv
->_W_mon_thousands_sep
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1142 MSVCRT__free_locale(loc
);
1146 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SPOSITIVESIGN
1147 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1148 if(i
&& (loc
->locinfo
->lconv
->_W_positive_sign
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1149 memcpy(loc
->locinfo
->lconv
->_W_positive_sign
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1151 MSVCRT__free_locale(loc
);
1155 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SNEGATIVESIGN
1156 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1157 if(i
&& (loc
->locinfo
->lconv
->_W_negative_sign
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1158 memcpy(loc
->locinfo
->lconv
->_W_negative_sign
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1160 MSVCRT__free_locale(loc
);
1166 loc
->locinfo
->lconv
->int_curr_symbol
= MSVCRT_malloc(sizeof(char));
1167 loc
->locinfo
->lconv
->currency_symbol
= MSVCRT_malloc(sizeof(char));
1168 loc
->locinfo
->lconv
->mon_decimal_point
= MSVCRT_malloc(sizeof(char));
1169 loc
->locinfo
->lconv
->mon_thousands_sep
= MSVCRT_malloc(sizeof(char));
1170 loc
->locinfo
->lconv
->mon_grouping
= MSVCRT_malloc(sizeof(char));
1171 loc
->locinfo
->lconv
->positive_sign
= MSVCRT_malloc(sizeof(char));
1172 loc
->locinfo
->lconv
->negative_sign
= MSVCRT_malloc(sizeof(char));
1174 if(!loc
->locinfo
->lconv
->int_curr_symbol
|| !loc
->locinfo
->lconv
->currency_symbol
1175 || !loc
->locinfo
->lconv
->mon_decimal_point
|| !loc
->locinfo
->lconv
->mon_thousands_sep
1176 || !loc
->locinfo
->lconv
->mon_grouping
|| !loc
->locinfo
->lconv
->positive_sign
1177 || !loc
->locinfo
->lconv
->negative_sign
) {
1178 MSVCRT__free_locale(loc
);
1182 loc
->locinfo
->lconv
->int_curr_symbol
[0] = '\0';
1183 loc
->locinfo
->lconv
->currency_symbol
[0] = '\0';
1184 loc
->locinfo
->lconv
->mon_decimal_point
[0] = '\0';
1185 loc
->locinfo
->lconv
->mon_thousands_sep
[0] = '\0';
1186 loc
->locinfo
->lconv
->mon_grouping
[0] = '\0';
1187 loc
->locinfo
->lconv
->positive_sign
[0] = '\0';
1188 loc
->locinfo
->lconv
->negative_sign
[0] = '\0';
1189 loc
->locinfo
->lconv
->int_frac_digits
= 127;
1190 loc
->locinfo
->lconv
->frac_digits
= 127;
1191 loc
->locinfo
->lconv
->p_cs_precedes
= 127;
1192 loc
->locinfo
->lconv
->p_sep_by_space
= 127;
1193 loc
->locinfo
->lconv
->n_cs_precedes
= 127;
1194 loc
->locinfo
->lconv
->n_sep_by_space
= 127;
1195 loc
->locinfo
->lconv
->p_sign_posn
= 127;
1196 loc
->locinfo
->lconv
->n_sign_posn
= 127;
1198 #if _MSVCR_VER >= 120
1199 loc
->locinfo
->lconv
->_W_int_curr_symbol
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1200 loc
->locinfo
->lconv
->_W_currency_symbol
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1201 loc
->locinfo
->lconv
->_W_mon_decimal_point
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1202 loc
->locinfo
->lconv
->_W_mon_thousands_sep
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1203 loc
->locinfo
->lconv
->_W_positive_sign
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1204 loc
->locinfo
->lconv
->_W_negative_sign
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1206 if(!loc
->locinfo
->lconv
->_W_int_curr_symbol
|| !loc
->locinfo
->lconv
->_W_currency_symbol
1207 || !loc
->locinfo
->lconv
->_W_mon_decimal_point
|| !loc
->locinfo
->lconv
->_W_mon_thousands_sep
1208 || !loc
->locinfo
->lconv
->positive_sign
|| !loc
->locinfo
->lconv
->negative_sign
) {
1209 MSVCRT__free_locale(loc
);
1213 loc
->locinfo
->lconv
->_W_int_curr_symbol
[0] = '\0';
1214 loc
->locinfo
->lconv
->_W_currency_symbol
[0] = '\0';
1215 loc
->locinfo
->lconv
->_W_mon_decimal_point
[0] = '\0';
1216 loc
->locinfo
->lconv
->_W_mon_thousands_sep
[0] = '\0';
1217 loc
->locinfo
->lconv
->_W_positive_sign
[0] = '\0';
1218 loc
->locinfo
->lconv
->_W_negative_sign
[0] = '\0';
1221 loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
= MSVCRT__strdup("C");
1224 if(lcid
[MSVCRT_LC_NUMERIC
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_NUMERIC
)) {
1225 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_NUMERIC
], cp
[MSVCRT_LC_NUMERIC
], loc
, MSVCRT_LC_NUMERIC
)) {
1226 MSVCRT__free_locale(loc
);
1230 if(!loc
->locinfo
->lconv_intl_refcount
)
1231 loc
->locinfo
->lconv_intl_refcount
= MSVCRT_malloc(sizeof(int));
1232 loc
->locinfo
->lconv_num_refcount
= MSVCRT_malloc(sizeof(int));
1233 if(!loc
->locinfo
->lconv_intl_refcount
|| !loc
->locinfo
->lconv_num_refcount
) {
1234 MSVCRT__free_locale(loc
);
1238 *loc
->locinfo
->lconv_intl_refcount
= 1;
1239 *loc
->locinfo
->lconv_num_refcount
= 1;
1241 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SDECIMAL
1242 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1243 if(i
&& (loc
->locinfo
->lconv
->decimal_point
= MSVCRT_malloc(i
)))
1244 memcpy(loc
->locinfo
->lconv
->decimal_point
, buf
, i
);
1246 MSVCRT__free_locale(loc
);
1250 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_STHOUSAND
1251 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1252 if(i
&& (loc
->locinfo
->lconv
->thousands_sep
= MSVCRT_malloc(i
)))
1253 memcpy(loc
->locinfo
->lconv
->thousands_sep
, buf
, i
);
1255 MSVCRT__free_locale(loc
);
1259 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SGROUPING
1260 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1262 i
= i
/2 + (buf
[i
-2]=='0'?0:1);
1263 if(i
&& (loc
->locinfo
->lconv
->grouping
= MSVCRT_malloc(i
))) {
1264 for(i
=0; buf
[i
+1]==';'; i
+=2)
1265 loc
->locinfo
->lconv
->grouping
[i
/2] = buf
[i
]-'0';
1266 loc
->locinfo
->lconv
->grouping
[i
/2] = buf
[i
]-'0';
1268 loc
->locinfo
->lconv
->grouping
[i
/2+1] = 127;
1270 MSVCRT__free_locale(loc
);
1274 #if _MSVCR_VER >= 120
1275 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SDECIMAL
1276 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1277 if(i
&& (loc
->locinfo
->lconv
->_W_decimal_point
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1278 memcpy(loc
->locinfo
->lconv
->_W_decimal_point
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1280 MSVCRT__free_locale(loc
);
1284 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_STHOUSAND
1285 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1286 if(i
&& (loc
->locinfo
->lconv
->_W_thousands_sep
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1287 memcpy(loc
->locinfo
->lconv
->_W_thousands_sep
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1289 MSVCRT__free_locale(loc
);
1295 loc
->locinfo
->lconv
->decimal_point
= MSVCRT_malloc(sizeof(char[2]));
1296 loc
->locinfo
->lconv
->thousands_sep
= MSVCRT_malloc(sizeof(char));
1297 loc
->locinfo
->lconv
->grouping
= MSVCRT_malloc(sizeof(char));
1298 if(!loc
->locinfo
->lconv
->decimal_point
|| !loc
->locinfo
->lconv
->thousands_sep
1299 || !loc
->locinfo
->lconv
->grouping
) {
1300 MSVCRT__free_locale(loc
);
1304 loc
->locinfo
->lconv
->decimal_point
[0] = '.';
1305 loc
->locinfo
->lconv
->decimal_point
[1] = '\0';
1306 loc
->locinfo
->lconv
->thousands_sep
[0] = '\0';
1307 loc
->locinfo
->lconv
->grouping
[0] = '\0';
1309 #if _MSVCR_VER >= 120
1310 loc
->locinfo
->lconv
->_W_decimal_point
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
[2]));
1311 loc
->locinfo
->lconv
->_W_thousands_sep
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1313 if(!loc
->locinfo
->lconv
->_W_decimal_point
|| !loc
->locinfo
->lconv
->_W_thousands_sep
) {
1314 MSVCRT__free_locale(loc
);
1318 loc
->locinfo
->lconv
->_W_decimal_point
[0] = '.';
1319 loc
->locinfo
->lconv
->_W_decimal_point
[1] = '\0';
1320 loc
->locinfo
->lconv
->_W_thousands_sep
[0] = '\0';
1323 loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
= MSVCRT__strdup("C");
1326 if(lcid
[MSVCRT_LC_TIME
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_TIME
)) {
1327 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_TIME
], cp
[MSVCRT_LC_TIME
], loc
, MSVCRT_LC_TIME
)) {
1328 MSVCRT__free_locale(loc
);
1332 loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
= MSVCRT__strdup("C");
1334 size
= sizeof(MSVCRT___lc_time_data
);
1335 lcid_tmp
= lcid
[MSVCRT_LC_TIME
] ? lcid
[MSVCRT_LC_TIME
] : MAKELCID(LANG_ENGLISH
, SORT_DEFAULT
);
1336 for(i
=0; i
<sizeof(time_data
)/sizeof(time_data
[0]); i
++) {
1337 if(time_data
[i
]==LOCALE_SSHORTDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1338 size
+= sizeof(cloc_short_date
) + sizeof(cloc_short_dateW
);
1339 }else if(time_data
[i
]==LOCALE_SLONGDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1340 size
+= sizeof(cloc_long_date
) + sizeof(cloc_long_dateW
);
1342 ret
= GetLocaleInfoA(lcid_tmp
, time_data
[i
]
1343 |LOCALE_NOUSEROVERRIDE
, NULL
, 0);
1345 MSVCRT__free_locale(loc
);
1350 ret
= GetLocaleInfoW(lcid_tmp
, time_data
[i
]
1351 |LOCALE_NOUSEROVERRIDE
, NULL
, 0);
1353 MSVCRT__free_locale(loc
);
1356 size
+= ret
*sizeof(MSVCRT_wchar_t
);
1360 loc
->locinfo
->lc_time_curr
= MSVCRT_malloc(size
);
1361 if(!loc
->locinfo
->lc_time_curr
) {
1362 MSVCRT__free_locale(loc
);
1367 for(i
=0; i
<sizeof(time_data
)/sizeof(time_data
[0]); i
++) {
1368 loc
->locinfo
->lc_time_curr
->str
.str
[i
] = &loc
->locinfo
->lc_time_curr
->data
[ret
];
1369 if(time_data
[i
]==LOCALE_SSHORTDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1370 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_short_date
, sizeof(cloc_short_date
));
1371 ret
+= sizeof(cloc_short_date
);
1372 }else if(time_data
[i
]==LOCALE_SLONGDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1373 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_long_date
, sizeof(cloc_long_date
));
1374 ret
+= sizeof(cloc_long_date
);
1375 }else if(time_data
[i
]==LOCALE_STIMEFORMAT
&& !lcid
[MSVCRT_LC_TIME
]) {
1376 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_time
, sizeof(cloc_time
));
1377 ret
+= sizeof(cloc_time
);
1379 ret
+= GetLocaleInfoA(lcid_tmp
, time_data
[i
]|LOCALE_NOUSEROVERRIDE
,
1380 &loc
->locinfo
->lc_time_curr
->data
[ret
], size
-ret
);
1383 for(i
=0; i
<sizeof(time_data
)/sizeof(time_data
[0]); i
++) {
1384 loc
->locinfo
->lc_time_curr
->wstr
[i
] = (MSVCRT_wchar_t
*)&loc
->locinfo
->lc_time_curr
->data
[ret
];
1385 if(time_data
[i
]==LOCALE_SSHORTDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1386 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_short_dateW
, sizeof(cloc_short_dateW
));
1387 ret
+= sizeof(cloc_short_dateW
);
1388 }else if(time_data
[i
]==LOCALE_SLONGDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1389 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_long_dateW
, sizeof(cloc_long_dateW
));
1390 ret
+= sizeof(cloc_long_dateW
);
1391 }else if(time_data
[i
]==LOCALE_STIMEFORMAT
&& !lcid
[MSVCRT_LC_TIME
]) {
1392 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_timeW
, sizeof(cloc_timeW
));
1393 ret
+= sizeof(cloc_timeW
);
1395 ret
+= GetLocaleInfoW(lcid_tmp
, time_data
[i
]|LOCALE_NOUSEROVERRIDE
,
1396 (MSVCRT_wchar_t
*)&loc
->locinfo
->lc_time_curr
->data
[ret
], size
-ret
)*sizeof(MSVCRT_wchar_t
);
1399 loc
->locinfo
->lc_time_curr
->lcid
= lcid
[MSVCRT_LC_TIME
];
1404 /*********************************************************************
1405 * setlocale (MSVCRT.@)
1407 char* CDECL
MSVCRT_setlocale(int category
, const char* locale
)
1409 MSVCRT__locale_t loc
;
1410 MSVCRT_pthreadlocinfo locinfo
= get_locinfo();
1412 if(category
<MSVCRT_LC_MIN
|| category
>MSVCRT_LC_MAX
)
1416 if(category
== MSVCRT_LC_ALL
)
1417 return construct_lc_all(locinfo
);
1419 return locinfo
->lc_category
[category
].locale
;
1422 loc
= MSVCRT__create_locale(category
, locale
);
1424 WARN("%d %s failed\n", category
, locale
);
1432 case MSVCRT_LC_COLLATE
:
1433 locinfo
->lc_collate_cp
= loc
->locinfo
->lc_collate_cp
;
1434 locinfo
->lc_handle
[MSVCRT_LC_COLLATE
] =
1435 loc
->locinfo
->lc_handle
[MSVCRT_LC_COLLATE
];
1436 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
,
1437 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
);
1438 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_COLLATE
].refcount
,
1439 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].refcount
);
1441 if(category
!= MSVCRT_LC_ALL
)
1444 case MSVCRT_LC_CTYPE
:
1445 locinfo
->lc_handle
[MSVCRT_LC_CTYPE
] =
1446 loc
->locinfo
->lc_handle
[MSVCRT_LC_CTYPE
];
1447 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
,
1448 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
);
1449 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_CTYPE
].refcount
,
1450 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].refcount
);
1452 locinfo
->lc_codepage
= loc
->locinfo
->lc_codepage
;
1453 locinfo
->lc_clike
= loc
->locinfo
->lc_clike
;
1454 locinfo
->mb_cur_max
= loc
->locinfo
->mb_cur_max
;
1456 swap_pointers((void**)&locinfo
->ctype1_refcount
,
1457 (void**)&loc
->locinfo
->ctype1_refcount
);
1458 swap_pointers((void**)&locinfo
->ctype1
, (void**)&loc
->locinfo
->ctype1
);
1459 swap_pointers((void**)&locinfo
->pctype
, (void**)&loc
->locinfo
->pctype
);
1460 swap_pointers((void**)&locinfo
->pclmap
, (void**)&loc
->locinfo
->pclmap
);
1461 swap_pointers((void**)&locinfo
->pcumap
, (void**)&loc
->locinfo
->pcumap
);
1463 if(category
!= MSVCRT_LC_ALL
)
1466 case MSVCRT_LC_MONETARY
:
1467 locinfo
->lc_handle
[MSVCRT_LC_MONETARY
] =
1468 loc
->locinfo
->lc_handle
[MSVCRT_LC_MONETARY
];
1469 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
,
1470 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
);
1471 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_MONETARY
].refcount
,
1472 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].refcount
);
1474 swap_pointers((void**)&locinfo
->lconv
->int_curr_symbol
,
1475 (void**)&loc
->locinfo
->lconv
->int_curr_symbol
);
1476 swap_pointers((void**)&locinfo
->lconv
->currency_symbol
,
1477 (void**)&loc
->locinfo
->lconv
->currency_symbol
);
1478 swap_pointers((void**)&locinfo
->lconv
->mon_decimal_point
,
1479 (void**)&loc
->locinfo
->lconv
->mon_decimal_point
);
1480 swap_pointers((void**)&locinfo
->lconv
->mon_thousands_sep
,
1481 (void**)&loc
->locinfo
->lconv
->mon_thousands_sep
);
1482 swap_pointers((void**)&locinfo
->lconv
->mon_grouping
,
1483 (void**)&loc
->locinfo
->lconv
->mon_grouping
);
1484 swap_pointers((void**)&locinfo
->lconv
->positive_sign
,
1485 (void**)&loc
->locinfo
->lconv
->positive_sign
);
1486 swap_pointers((void**)&locinfo
->lconv
->negative_sign
,
1487 (void**)&loc
->locinfo
->lconv
->negative_sign
);
1489 #if _MSVCR_VER >= 120
1490 swap_pointers((void**)&locinfo
->lconv
->_W_int_curr_symbol
,
1491 (void**)&loc
->locinfo
->lconv
->_W_int_curr_symbol
);
1492 swap_pointers((void**)&locinfo
->lconv
->_W_currency_symbol
,
1493 (void**)&loc
->locinfo
->lconv
->_W_currency_symbol
);
1494 swap_pointers((void**)&locinfo
->lconv
->_W_mon_decimal_point
,
1495 (void**)&loc
->locinfo
->lconv
->_W_mon_decimal_point
);
1496 swap_pointers((void**)&locinfo
->lconv
->_W_mon_thousands_sep
,
1497 (void**)&loc
->locinfo
->lconv
->_W_mon_thousands_sep
);
1498 swap_pointers((void**)&locinfo
->lconv
->_W_positive_sign
,
1499 (void**)&loc
->locinfo
->lconv
->_W_positive_sign
);
1500 swap_pointers((void**)&locinfo
->lconv
->_W_negative_sign
,
1501 (void**)&loc
->locinfo
->lconv
->_W_negative_sign
);
1504 locinfo
->lconv
->int_frac_digits
= loc
->locinfo
->lconv
->int_frac_digits
;
1505 locinfo
->lconv
->frac_digits
= loc
->locinfo
->lconv
->frac_digits
;
1506 locinfo
->lconv
->p_cs_precedes
= loc
->locinfo
->lconv
->p_cs_precedes
;
1507 locinfo
->lconv
->p_sep_by_space
= loc
->locinfo
->lconv
->p_sep_by_space
;
1508 locinfo
->lconv
->n_cs_precedes
= loc
->locinfo
->lconv
->n_cs_precedes
;
1509 locinfo
->lconv
->n_sep_by_space
= loc
->locinfo
->lconv
->n_sep_by_space
;
1510 locinfo
->lconv
->p_sign_posn
= loc
->locinfo
->lconv
->p_sign_posn
;
1511 locinfo
->lconv
->n_sign_posn
= loc
->locinfo
->lconv
->n_sign_posn
;
1513 if(category
!= MSVCRT_LC_ALL
)
1516 case MSVCRT_LC_NUMERIC
:
1517 locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
] =
1518 loc
->locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
];
1519 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
,
1520 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
);
1521 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].refcount
,
1522 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].refcount
);
1524 swap_pointers((void**)&locinfo
->lconv
->decimal_point
,
1525 (void**)&loc
->locinfo
->lconv
->decimal_point
);
1526 swap_pointers((void**)&locinfo
->lconv
->thousands_sep
,
1527 (void**)&loc
->locinfo
->lconv
->thousands_sep
);
1528 swap_pointers((void**)&locinfo
->lconv
->grouping
,
1529 (void**)&loc
->locinfo
->lconv
->grouping
);
1531 #if _MSVCR_VER >= 120
1532 swap_pointers((void**)&locinfo
->lconv
->_W_decimal_point
,
1533 (void**)&loc
->locinfo
->lconv
->_W_decimal_point
);
1534 swap_pointers((void**)&locinfo
->lconv
->_W_thousands_sep
,
1535 (void**)&loc
->locinfo
->lconv
->_W_thousands_sep
);
1538 if(category
!= MSVCRT_LC_ALL
)
1541 case MSVCRT_LC_TIME
:
1542 locinfo
->lc_handle
[MSVCRT_LC_TIME
] =
1543 loc
->locinfo
->lc_handle
[MSVCRT_LC_TIME
];
1544 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
,
1545 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
);
1546 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_TIME
].refcount
,
1547 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].refcount
);
1548 swap_pointers((void**)&locinfo
->lc_time_curr
,
1549 (void**)&loc
->locinfo
->lc_time_curr
);
1551 if(category
!= MSVCRT_LC_ALL
)
1555 MSVCRT__free_locale(loc
);
1558 if(locinfo
== MSVCRT_locale
->locinfo
) {
1561 MSVCRT___lc_codepage
= locinfo
->lc_codepage
;
1562 MSVCRT___lc_collate_cp
= locinfo
->lc_collate_cp
;
1563 MSVCRT___mb_cur_max
= locinfo
->mb_cur_max
;
1564 MSVCRT__pctype
= locinfo
->pctype
;
1565 for(i
=MSVCRT_LC_MIN
; i
<=MSVCRT_LC_MAX
; i
++)
1566 MSVCRT___lc_handle
[i
] = MSVCRT_locale
->locinfo
->lc_handle
[i
];
1569 if(category
== MSVCRT_LC_ALL
)
1570 return construct_lc_all(locinfo
);
1572 return locinfo
->lc_category
[category
].locale
;
1575 /*********************************************************************
1576 * _wsetlocale (MSVCRT.@)
1578 MSVCRT_wchar_t
* CDECL
MSVCRT__wsetlocale(int category
, const MSVCRT_wchar_t
* wlocale
)
1580 static MSVCRT_wchar_t current_lc_all
[MAX_LOCALE_LENGTH
];
1582 char *locale
= NULL
;
1587 len
= MSVCRT_wcstombs(NULL
, wlocale
, 0);
1591 locale
= MSVCRT_malloc(++len
);
1595 MSVCRT_wcstombs(locale
, wlocale
, len
);
1599 ret
= MSVCRT_setlocale(category
, locale
);
1600 MSVCRT_free(locale
);
1602 if(ret
&& MSVCRT_mbstowcs(current_lc_all
, ret
, MAX_LOCALE_LENGTH
)==-1)
1606 return ret
? current_lc_all
: NULL
;
1609 /*********************************************************************
1610 * _configthreadlocale (MSVCR80.@)
1612 int CDECL
_configthreadlocale(int type
)
1614 thread_data_t
*data
= msvcrt_get_thread_data();
1615 MSVCRT__locale_t locale
;
1621 ret
= (data
->have_locale
? MSVCRT__ENABLE_PER_THREAD_LOCALE
: MSVCRT__DISABLE_PER_THREAD_LOCALE
);
1623 if(type
== MSVCRT__ENABLE_PER_THREAD_LOCALE
) {
1624 if(!data
->have_locale
) {
1625 /* Copy current global locale */
1626 locale
= MSVCRT__create_locale(MSVCRT_LC_ALL
, MSVCRT_setlocale(MSVCRT_LC_ALL
, NULL
));
1630 data
->locinfo
= locale
->locinfo
;
1631 data
->mbcinfo
= locale
->mbcinfo
;
1632 data
->have_locale
= TRUE
;
1633 MSVCRT_free(locale
);
1639 if(type
== MSVCRT__DISABLE_PER_THREAD_LOCALE
) {
1640 if(data
->have_locale
) {
1641 free_locinfo(data
->locinfo
);
1642 free_mbcinfo(data
->mbcinfo
);
1643 data
->locinfo
= MSVCRT_locale
->locinfo
;
1644 data
->mbcinfo
= MSVCRT_locale
->mbcinfo
;
1645 data
->have_locale
= FALSE
;
1657 BOOL
msvcrt_init_locale(void)
1662 MSVCRT_locale
= MSVCRT__create_locale(0, "C");
1667 MSVCRT___lc_codepage
= MSVCRT_locale
->locinfo
->lc_codepage
;
1668 MSVCRT___lc_collate_cp
= MSVCRT_locale
->locinfo
->lc_collate_cp
;
1669 MSVCRT___mb_cur_max
= MSVCRT_locale
->locinfo
->mb_cur_max
;
1670 MSVCRT__pctype
= MSVCRT_locale
->locinfo
->pctype
;
1671 for(i
=MSVCRT_LC_MIN
; i
<=MSVCRT_LC_MAX
; i
++)
1672 MSVCRT___lc_handle
[i
] = MSVCRT_locale
->locinfo
->lc_handle
[i
];
1673 _setmbcp(_MB_CP_ANSI
);