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"
38 #include "wine/unicode.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
42 #define MAX_ELEM_LEN 64 /* Max length of country/language/CP string */
43 #define MAX_LOCALE_LENGTH 256
44 MSVCRT__locale_t MSVCRT_locale
= NULL
;
45 unsigned short *MSVCRT__pctype
= NULL
;
46 unsigned int MSVCRT___lc_codepage
= 0;
47 int MSVCRT___lc_collate_cp
= 0;
48 LCID MSVCRT___lc_handle
[MSVCRT_LC_MAX
- MSVCRT_LC_MIN
+ 1] = { 0 };
49 int MSVCRT___mb_cur_max
= 1;
50 static unsigned char charmax
= CHAR_MAX
;
53 #define LOCK_LOCALE _mlock(_SETLOCALE_LOCK);
54 #define UNLOCK_LOCALE _munlock(_SETLOCALE_LOCK);
56 #define MSVCRT_LEADBYTE 0x8000
57 #define MSVCRT_C1_DEFINED 0x200
59 /* Friendly country strings & language names abbreviations. */
60 static const char * const _country_synonyms
[] =
63 "american english", "enu",
64 "american-english", "enu",
65 "english-american", "enu",
73 "french-belgian", "frb",
76 "french-canadian", "frc",
78 "chinese-simplified", "chs",
79 "chinese-traditional", "cht",
80 "dutch-belgian", "nlb",
84 "french-swiss", "frs",
86 "german-swiss", "des",
87 "italian-swiss", "its",
88 "german-austrian", "dea",
90 "portuguese-brazil", "ptb",
91 "spanish-mexican", "esm",
92 "norwegian-bokmal", "nor",
93 "norwegian-nynorsk", "non",
94 "spanish-modern", "esn"
97 /* INTERNAL: Map a synonym to an ISO code */
98 static void remap_synonym(char *name
)
101 for (i
= 0; i
< sizeof(_country_synonyms
)/sizeof(char*); i
+= 2 )
103 if (!strcasecmp(_country_synonyms
[i
],name
))
105 TRACE(":Mapping synonym %s to %s\n",name
,_country_synonyms
[i
+1]);
106 strcpy(name
, _country_synonyms
[i
+1]);
112 /* Note: Flags are weighted in order of matching importance */
113 #define FOUND_LANGUAGE 0x4
114 #define FOUND_COUNTRY 0x2
115 #define FOUND_CODEPAGE 0x1
118 char search_language
[MAX_ELEM_LEN
];
119 char search_country
[MAX_ELEM_LEN
];
120 char search_codepage
[MAX_ELEM_LEN
];
121 char found_codepage
[MAX_ELEM_LEN
];
122 unsigned int match_flags
;
123 LANGID found_lang_id
;
126 #define CONTINUE_LOOKING TRUE
127 #define STOP_LOOKING FALSE
129 /* INTERNAL: Get and compare locale info with a given string */
130 static int compare_info(LCID lcid
, DWORD flags
, char* buff
, const char* cmp
, BOOL exact
)
138 GetLocaleInfoA(lcid
, flags
|LOCALE_NOUSEROVERRIDE
, buff
, MAX_ELEM_LEN
);
142 /* Partial matches are only allowed on language/country names */
145 return !strcasecmp(cmp
, buff
);
147 return !strncasecmp(cmp
, buff
, len
);
151 find_best_locale_proc(HMODULE hModule
, LPCSTR type
, LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
153 locale_search_t
*res
= (locale_search_t
*)lParam
;
154 const LCID lcid
= MAKELCID(LangID
, SORT_DEFAULT
);
155 char buff
[MAX_ELEM_LEN
];
156 unsigned int flags
= 0;
158 if(PRIMARYLANGID(LangID
) == LANG_NEUTRAL
)
159 return CONTINUE_LOOKING
;
162 if (compare_info(lcid
,LOCALE_SISO639LANGNAME
,buff
,res
->search_language
, TRUE
) ||
163 compare_info(lcid
,LOCALE_SABBREVLANGNAME
,buff
,res
->search_language
, TRUE
) ||
164 compare_info(lcid
,LOCALE_SENGLANGUAGE
,buff
,res
->search_language
, FALSE
))
166 TRACE(":Found language: %s->%s\n", res
->search_language
, buff
);
167 flags
|= FOUND_LANGUAGE
;
169 else if (res
->match_flags
& FOUND_LANGUAGE
)
171 return CONTINUE_LOOKING
;
175 if (compare_info(lcid
,LOCALE_SISO3166CTRYNAME
,buff
,res
->search_country
, TRUE
) ||
176 compare_info(lcid
,LOCALE_SABBREVCTRYNAME
,buff
,res
->search_country
, TRUE
) ||
177 compare_info(lcid
,LOCALE_SENGCOUNTRY
,buff
,res
->search_country
, FALSE
))
179 TRACE("Found country:%s->%s\n", res
->search_country
, buff
);
180 flags
|= FOUND_COUNTRY
;
182 else if (!flags
&& (res
->match_flags
& FOUND_COUNTRY
))
184 return CONTINUE_LOOKING
;
188 if (compare_info(lcid
,LOCALE_IDEFAULTCODEPAGE
,buff
,res
->search_codepage
, TRUE
) ||
189 (compare_info(lcid
,LOCALE_IDEFAULTANSICODEPAGE
,buff
,res
->search_codepage
, TRUE
)))
191 TRACE("Found codepage:%s->%s\n", res
->search_codepage
, buff
);
192 flags
|= FOUND_CODEPAGE
;
193 memcpy(res
->found_codepage
,res
->search_codepage
,MAX_ELEM_LEN
);
195 else if (!flags
&& (res
->match_flags
& FOUND_CODEPAGE
))
197 return CONTINUE_LOOKING
;
200 if (flags
> res
->match_flags
)
202 /* Found a better match than previously */
203 res
->match_flags
= flags
;
204 res
->found_lang_id
= LangID
;
206 if ((flags
& (FOUND_LANGUAGE
| FOUND_COUNTRY
| FOUND_CODEPAGE
)) ==
207 (FOUND_LANGUAGE
| FOUND_COUNTRY
| FOUND_CODEPAGE
))
209 TRACE(":found exact locale match\n");
212 return CONTINUE_LOOKING
;
215 extern int atoi(const char *);
217 /* Internal: Find the LCID for a locale specification */
218 LCID
MSVCRT_locale_to_LCID(const char *locale
, unsigned short *codepage
)
221 locale_search_t search
;
222 const char *cp
, *region
;
224 memset(&search
, 0, sizeof(locale_search_t
));
226 cp
= strchr(locale
, '.');
227 region
= strchr(locale
, '_');
229 lstrcpynA(search
.search_language
, locale
, MAX_ELEM_LEN
);
231 lstrcpynA(search
.search_country
, region
+1, MAX_ELEM_LEN
);
232 if(region
-locale
< MAX_ELEM_LEN
)
233 search
.search_language
[region
-locale
] = '\0';
235 search
.search_country
[0] = '\0';
238 lstrcpynA(search
.search_codepage
, cp
+1, MAX_ELEM_LEN
);
239 if(region
&& cp
-region
-1<MAX_ELEM_LEN
)
240 search
.search_country
[cp
-region
-1] = '\0';
241 if(cp
-locale
< MAX_ELEM_LEN
)
242 search
.search_language
[cp
-locale
] = '\0';
244 search
.search_codepage
[0] = '\0';
246 if(!search
.search_country
[0] && !search
.search_codepage
[0])
247 remap_synonym(search
.search_language
);
249 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), (LPSTR
)RT_STRING
,
250 (LPCSTR
)LOCALE_ILANGUAGE
,find_best_locale_proc
,
253 if (!search
.match_flags
)
256 /* If we were given something that didn't match, fail */
257 if (search
.search_country
[0] && !(search
.match_flags
& FOUND_COUNTRY
))
260 lcid
= MAKELCID(search
.found_lang_id
, SORT_DEFAULT
);
262 /* Populate partial locale, translating LCID to locale string elements */
263 if (!(search
.match_flags
& FOUND_CODEPAGE
)) {
264 /* Even if a codepage is not enumerated for a locale
265 * it can be set if valid */
266 if (search
.search_codepage
[0]) {
267 if (IsValidCodePage(atoi(search
.search_codepage
)))
268 memcpy(search
.found_codepage
,search
.search_codepage
,MAX_ELEM_LEN
);
270 /* Special codepage values: OEM & ANSI */
271 if (!strcasecmp(search
.search_codepage
,"OCP")) {
272 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTCODEPAGE
,
273 search
.found_codepage
, MAX_ELEM_LEN
);
274 } else if (!strcasecmp(search
.search_codepage
,"ACP")) {
275 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
,
276 search
.found_codepage
, MAX_ELEM_LEN
);
280 if (!atoi(search
.found_codepage
))
284 /* Prefer ANSI codepages if present */
285 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
,
286 search
.found_codepage
, MAX_ELEM_LEN
);
287 if (!search
.found_codepage
[0] || !atoi(search
.found_codepage
))
288 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTCODEPAGE
,
289 search
.found_codepage
, MAX_ELEM_LEN
);
293 *codepage
= atoi(search
.found_codepage
);
298 /* INTERNAL: Set lc_handle, lc_id and lc_category in threadlocinfo struct */
299 static BOOL
update_threadlocinfo_category(LCID lcid
, unsigned short cp
,
300 MSVCRT__locale_t loc
, int category
)
305 if(GetLocaleInfoA(lcid
, LOCALE_ILANGUAGE
|LOCALE_NOUSEROVERRIDE
, buf
, 256)) {
308 loc
->locinfo
->lc_id
[category
].wLanguage
= 0;
310 loc
->locinfo
->lc_id
[category
].wLanguage
*= 16;
313 loc
->locinfo
->lc_id
[category
].wLanguage
+= *p
-'0';
315 loc
->locinfo
->lc_id
[category
].wLanguage
+= *p
-'a'+10;
320 loc
->locinfo
->lc_id
[category
].wCountry
=
321 loc
->locinfo
->lc_id
[category
].wLanguage
;
324 loc
->locinfo
->lc_id
[category
].wCodePage
= cp
;
326 loc
->locinfo
->lc_handle
[category
] = lcid
;
329 len
+= GetLocaleInfoA(lcid
, LOCALE_SENGLANGUAGE
330 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
332 len
+= GetLocaleInfoA(lcid
, LOCALE_SENGCOUNTRY
333 |LOCALE_NOUSEROVERRIDE
, &buf
[len
], 256-len
);
335 sprintf(buf
+len
, "%d", cp
);
336 len
+= strlen(buf
+len
)+1;
338 loc
->locinfo
->lc_category
[category
].locale
= MSVCRT_malloc(len
);
339 loc
->locinfo
->lc_category
[category
].refcount
= MSVCRT_malloc(sizeof(int));
340 if(!loc
->locinfo
->lc_category
[category
].locale
341 || !loc
->locinfo
->lc_category
[category
].refcount
) {
342 MSVCRT_free(loc
->locinfo
->lc_category
[category
].locale
);
343 MSVCRT_free(loc
->locinfo
->lc_category
[category
].refcount
);
344 loc
->locinfo
->lc_category
[category
].locale
= NULL
;
345 loc
->locinfo
->lc_category
[category
].refcount
= NULL
;
348 memcpy(loc
->locinfo
->lc_category
[category
].locale
, buf
, len
);
349 *loc
->locinfo
->lc_category
[category
].refcount
= 1;
354 /* INTERNAL: swap pointers values */
355 static inline void swap_pointers(void **p1
, void **p2
) {
363 /* INTERNAL: returns pthreadlocinfo struct */
364 MSVCRT_pthreadlocinfo
get_locinfo(void) {
365 thread_data_t
*data
= msvcrt_get_thread_data();
367 if(!data
|| !data
->have_locale
)
368 return MSVCRT_locale
->locinfo
;
370 return data
->locinfo
;
373 /* INTERNAL: returns pthreadlocinfo struct */
374 MSVCRT_pthreadmbcinfo
get_mbcinfo(void) {
375 thread_data_t
*data
= msvcrt_get_thread_data();
377 if(!data
|| !data
->have_locale
)
378 return MSVCRT_locale
->mbcinfo
;
380 return data
->mbcinfo
;
383 /* INTERNAL: constructs string returned by setlocale */
384 static inline char* construct_lc_all(MSVCRT_pthreadlocinfo locinfo
) {
385 static char current_lc_all
[MAX_LOCALE_LENGTH
];
389 for(i
=MSVCRT_LC_MIN
+1; i
<MSVCRT_LC_MAX
; i
++) {
390 if(strcmp(locinfo
->lc_category
[i
].locale
,
391 locinfo
->lc_category
[i
+1].locale
))
396 return locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
;
398 sprintf(current_lc_all
,
399 "LC_COLLATE=%s;LC_CTYPE=%s;LC_MONETARY=%s;LC_NUMERIC=%s;LC_TIME=%s",
400 locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
,
401 locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
,
402 locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
,
403 locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
,
404 locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
);
406 return current_lc_all
;
410 /*********************************************************************
411 * _Getdays (MSVCRT.@)
413 char* CDECL
_Getdays(void)
415 MSVCRT___lc_time_data
*cur
= get_locinfo()->lc_time_curr
;
421 size
= cur
->str
.names
.short_mon
[0]-cur
->str
.names
.short_wday
[0];
422 out
= MSVCRT_malloc(size
+1);
429 len
= strlen(cur
->str
.names
.short_wday
[i
]);
430 memcpy(&out
[size
], cur
->str
.names
.short_wday
[i
], len
);
434 len
= strlen(cur
->str
.names
.wday
[i
]);
435 memcpy(&out
[size
], cur
->str
.names
.wday
[i
], len
);
443 /*********************************************************************
444 * _W_Getdays (MSVCRT.@)
446 MSVCRT_wchar_t
* CDECL
_W_Getdays(void)
448 MSVCRT___lc_time_data
*cur
= get_locinfo()->lc_time_curr
;
454 size
= cur
->wstr
.names
.short_mon
[0]-cur
->wstr
.names
.short_wday
[0];
455 out
= MSVCRT_malloc((size
+1)*sizeof(*out
));
462 len
= strlenW(cur
->wstr
.names
.short_wday
[i
]);
463 memcpy(&out
[size
], cur
->wstr
.names
.short_wday
[i
], len
*sizeof(*out
));
467 len
= strlenW(cur
->wstr
.names
.wday
[i
]);
468 memcpy(&out
[size
], cur
->wstr
.names
.wday
[i
], len
*sizeof(*out
));
476 /*********************************************************************
477 * _Getmonths (MSVCRT.@)
479 char* CDECL
_Getmonths(void)
481 MSVCRT___lc_time_data
*cur
= get_locinfo()->lc_time_curr
;
487 size
= cur
->str
.names
.am
-cur
->str
.names
.short_mon
[0];
488 out
= MSVCRT_malloc(size
+1);
493 for(i
=0; i
<12; i
++) {
495 len
= strlen(cur
->str
.names
.short_mon
[i
]);
496 memcpy(&out
[size
], cur
->str
.names
.short_mon
[i
], len
);
500 len
= strlen(cur
->str
.names
.mon
[i
]);
501 memcpy(&out
[size
], cur
->str
.names
.mon
[i
], len
);
509 /*********************************************************************
510 * _Gettnames (MSVCRT.@)
512 void* CDECL
_Gettnames(void)
514 MSVCRT___lc_time_data
*ret
, *cur
= get_locinfo()->lc_time_curr
;
515 unsigned int i
, size
= sizeof(MSVCRT___lc_time_data
);
519 for(i
=0; i
<sizeof(cur
->str
.str
)/sizeof(cur
->str
.str
[0]); i
++)
520 size
+= strlen(cur
->str
.str
[i
])+1;
522 ret
= MSVCRT_malloc(size
);
525 memcpy(ret
, cur
, size
);
528 for(i
=0; i
<sizeof(cur
->str
.str
)/sizeof(cur
->str
.str
[0]); i
++) {
529 ret
->str
.str
[i
] = &ret
->data
[size
];
530 size
+= strlen(&ret
->data
[size
])+1;
536 /*********************************************************************
537 * __crtLCMapStringA (MSVCRT.@)
539 int CDECL
__crtLCMapStringA(
540 LCID lcid
, DWORD mapflags
, const char* src
, int srclen
, char* dst
,
541 int dstlen
, unsigned int codepage
, int xflag
543 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
544 lcid
,mapflags
,src
,srclen
,dst
,dstlen
,codepage
,xflag
);
545 /* FIXME: A bit incorrect. But msvcrt itself just converts its
546 * arguments to wide strings and then calls LCMapStringW
548 return LCMapStringA(lcid
,mapflags
,src
,srclen
,dst
,dstlen
);
551 /*********************************************************************
552 * __crtLCMapStringW (MSVCRT.@)
554 int CDECL
__crtLCMapStringW(LCID lcid
, DWORD mapflags
, const MSVCRT_wchar_t
*src
,
555 int srclen
, MSVCRT_wchar_t
*dst
, int dstlen
, unsigned int codepage
, int xflag
)
557 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
558 lcid
, mapflags
, debugstr_w(src
), srclen
, dst
, dstlen
, codepage
, xflag
);
560 return LCMapStringW(lcid
, mapflags
, src
, srclen
, dst
, dstlen
);
563 /*********************************************************************
564 * __crtCompareStringA (MSVCRT.@)
566 int CDECL
__crtCompareStringA( LCID lcid
, DWORD flags
, const char *src1
, int len1
,
567 const char *src2
, int len2
)
569 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
570 lcid
, flags
, debugstr_a(src1
), len1
, debugstr_a(src2
), len2
);
571 /* FIXME: probably not entirely right */
572 return CompareStringA( lcid
, flags
, src1
, len1
, src2
, len2
);
575 /*********************************************************************
576 * __crtCompareStringW (MSVCRT.@)
578 int CDECL
__crtCompareStringW( LCID lcid
, DWORD flags
, const MSVCRT_wchar_t
*src1
, int len1
,
579 const MSVCRT_wchar_t
*src2
, int len2
)
581 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
582 lcid
, flags
, debugstr_w(src1
), len1
, debugstr_w(src2
), len2
);
583 /* FIXME: probably not entirely right */
584 return CompareStringW( lcid
, flags
, src1
, len1
, src2
, len2
);
587 /*********************************************************************
588 * __crtGetLocaleInfoW (MSVCRT.@)
590 int CDECL
__crtGetLocaleInfoW( LCID lcid
, LCTYPE type
, MSVCRT_wchar_t
*buffer
, int len
)
592 FIXME("(lcid %x, type %x, %p(%d), partial stub\n", lcid
, type
, buffer
, len
);
593 /* FIXME: probably not entirely right */
594 return GetLocaleInfoW( lcid
, type
, buffer
, len
);
597 /*********************************************************************
600 MSVCRT_wint_t CDECL
MSVCRT_btowc(int c
)
602 unsigned char letter
= c
;
605 if(!MultiByteToWideChar(get_locinfo()->lc_handle
[MSVCRT_LC_CTYPE
],
606 0, (LPCSTR
)&letter
, 1, &ret
, 1))
612 /*********************************************************************
613 * __crtGetStringTypeW(MSVCRT.@)
615 * This function was accepting different number of arguments in older
616 * versions of msvcrt.
618 BOOL CDECL
__crtGetStringTypeW(DWORD unk
, DWORD type
,
619 MSVCRT_wchar_t
*buffer
, int len
, WORD
*out
)
621 FIXME("(unk %x, type %x, wstr %p(%d), %p) partial stub\n",
622 unk
, type
, buffer
, len
, out
);
624 return GetStringTypeW(type
, buffer
, len
, out
);
627 /*********************************************************************
628 * localeconv (MSVCRT.@)
630 struct MSVCRT_lconv
* CDECL
MSVCRT_localeconv(void)
632 return get_locinfo()->lconv
;
635 /*********************************************************************
636 * __lconv_init (MSVCRT.@)
638 int CDECL
__lconv_init(void)
640 /* this is used to make chars unsigned */
645 /*********************************************************************
646 * ___lc_handle_func (MSVCRT.@)
648 LCID
* CDECL
___lc_handle_func(void)
650 return get_locinfo()->lc_handle
;
653 /*********************************************************************
654 * ___lc_codepage_func (MSVCRT.@)
656 unsigned int CDECL
___lc_codepage_func(void)
658 return get_locinfo()->lc_codepage
;
661 /*********************************************************************
662 * ___lc_collate_cp_func (MSVCRT.@)
664 int CDECL
___lc_collate_cp_func(void)
666 return get_locinfo()->lc_collate_cp
;
669 /* INTERNAL: frees MSVCRT_pthreadlocinfo struct */
670 void free_locinfo(MSVCRT_pthreadlocinfo locinfo
)
677 if(InterlockedDecrement(&locinfo
->refcount
))
680 for(i
=MSVCRT_LC_MIN
+1; i
<=MSVCRT_LC_MAX
; i
++) {
681 MSVCRT_free(locinfo
->lc_category
[i
].locale
);
682 MSVCRT_free(locinfo
->lc_category
[i
].refcount
);
686 MSVCRT_free(locinfo
->lconv
->decimal_point
);
687 MSVCRT_free(locinfo
->lconv
->thousands_sep
);
688 MSVCRT_free(locinfo
->lconv
->grouping
);
689 MSVCRT_free(locinfo
->lconv
->int_curr_symbol
);
690 MSVCRT_free(locinfo
->lconv
->currency_symbol
);
691 MSVCRT_free(locinfo
->lconv
->mon_decimal_point
);
692 MSVCRT_free(locinfo
->lconv
->mon_thousands_sep
);
693 MSVCRT_free(locinfo
->lconv
->mon_grouping
);
694 MSVCRT_free(locinfo
->lconv
->positive_sign
);
695 MSVCRT_free(locinfo
->lconv
->negative_sign
);
696 #if _MSVCR_VER >= 120
697 MSVCRT_free(locinfo
->lconv
->_W_decimal_point
);
698 MSVCRT_free(locinfo
->lconv
->_W_thousands_sep
);
699 MSVCRT_free(locinfo
->lconv
->_W_int_curr_symbol
);
700 MSVCRT_free(locinfo
->lconv
->_W_currency_symbol
);
701 MSVCRT_free(locinfo
->lconv
->_W_mon_decimal_point
);
702 MSVCRT_free(locinfo
->lconv
->_W_mon_thousands_sep
);
703 MSVCRT_free(locinfo
->lconv
->_W_positive_sign
);
704 MSVCRT_free(locinfo
->lconv
->_W_negative_sign
);
707 MSVCRT_free(locinfo
->lconv_intl_refcount
);
708 MSVCRT_free(locinfo
->lconv_num_refcount
);
709 MSVCRT_free(locinfo
->lconv_mon_refcount
);
710 MSVCRT_free(locinfo
->lconv
);
712 MSVCRT_free(locinfo
->ctype1_refcount
);
713 MSVCRT_free(locinfo
->ctype1
);
715 MSVCRT_free(locinfo
->pclmap
);
716 MSVCRT_free(locinfo
->pcumap
);
718 MSVCRT_free(locinfo
->lc_time_curr
);
720 MSVCRT_free(locinfo
);
723 /* INTERNAL: frees MSVCRT_pthreadmbcinfo struct */
724 void free_mbcinfo(MSVCRT_pthreadmbcinfo mbcinfo
)
729 if(InterlockedDecrement(&mbcinfo
->refcount
))
732 MSVCRT_free(mbcinfo
);
735 /*********************************************************************
736 * _get_current_locale (MSVCRT.@)
738 MSVCRT__locale_t CDECL
MSVCRT__get_current_locale(void)
740 MSVCRT__locale_t loc
= MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct
));
744 loc
->locinfo
= get_locinfo();
745 loc
->mbcinfo
= get_mbcinfo();
746 InterlockedIncrement(&loc
->locinfo
->refcount
);
747 InterlockedIncrement(&loc
->mbcinfo
->refcount
);
751 /*********************************************************************
752 * _free_locale (MSVCRT.@)
754 void CDECL
MSVCRT__free_locale(MSVCRT__locale_t locale
)
759 free_locinfo(locale
->locinfo
);
760 free_mbcinfo(locale
->mbcinfo
);
764 /*********************************************************************
765 * _create_locale (MSVCRT.@)
767 MSVCRT__locale_t CDECL
MSVCRT__create_locale(int category
, const char *locale
)
769 static const DWORD time_data
[] = {
770 LOCALE_SABBREVDAYNAME7
, LOCALE_SABBREVDAYNAME1
, LOCALE_SABBREVDAYNAME2
,
771 LOCALE_SABBREVDAYNAME3
, LOCALE_SABBREVDAYNAME4
, LOCALE_SABBREVDAYNAME5
,
772 LOCALE_SABBREVDAYNAME6
,
773 LOCALE_SDAYNAME7
, LOCALE_SDAYNAME1
, LOCALE_SDAYNAME2
, LOCALE_SDAYNAME3
,
774 LOCALE_SDAYNAME4
, LOCALE_SDAYNAME5
, LOCALE_SDAYNAME6
,
775 LOCALE_SABBREVMONTHNAME1
, LOCALE_SABBREVMONTHNAME2
, LOCALE_SABBREVMONTHNAME3
,
776 LOCALE_SABBREVMONTHNAME4
, LOCALE_SABBREVMONTHNAME5
, LOCALE_SABBREVMONTHNAME6
,
777 LOCALE_SABBREVMONTHNAME7
, LOCALE_SABBREVMONTHNAME8
, LOCALE_SABBREVMONTHNAME9
,
778 LOCALE_SABBREVMONTHNAME10
, LOCALE_SABBREVMONTHNAME11
, LOCALE_SABBREVMONTHNAME12
,
779 LOCALE_SMONTHNAME1
, LOCALE_SMONTHNAME2
, LOCALE_SMONTHNAME3
, LOCALE_SMONTHNAME4
,
780 LOCALE_SMONTHNAME5
, LOCALE_SMONTHNAME6
, LOCALE_SMONTHNAME7
, LOCALE_SMONTHNAME8
,
781 LOCALE_SMONTHNAME9
, LOCALE_SMONTHNAME10
, LOCALE_SMONTHNAME11
, LOCALE_SMONTHNAME12
,
782 LOCALE_S1159
, LOCALE_S2359
,
783 LOCALE_SSHORTDATE
, LOCALE_SLONGDATE
,
786 static const char collate
[] = "COLLATE=";
787 static const char ctype
[] = "CTYPE=";
788 static const char monetary
[] = "MONETARY=";
789 static const char numeric
[] = "NUMERIC=";
790 static const char time
[] = "TIME=";
791 static const char cloc_short_date
[] = "MM/dd/yy";
792 static const MSVCRT_wchar_t cloc_short_dateW
[] = {'M','M','/','d','d','/','y','y',0};
793 static const char cloc_long_date
[] = "dddd, MMMM dd, yyyy";
794 static const MSVCRT_wchar_t cloc_long_dateW
[] = {'d','d','d','d',',',' ','M','M','M','M',' ','d','d',',',' ','y','y','y','y',0};
795 static const char cloc_time
[] = "HH:mm:ss";
796 static const MSVCRT_wchar_t cloc_timeW
[] = {'H','H',':','m','m',':','s','s',0};
798 MSVCRT__locale_t loc
;
799 LCID lcid
[6] = { 0 }, lcid_tmp
;
800 unsigned short cp
[6] = { 0 };
802 #if _MSVCR_VER >= 120
803 MSVCRT_wchar_t wbuf
[256];
807 TRACE("(%d %s)\n", category
, locale
);
809 if(category
<MSVCRT_LC_MIN
|| category
>MSVCRT_LC_MAX
|| !locale
)
812 if(locale
[0]=='C' && !locale
[1]) {
815 } else if(!locale
[0]) {
816 lcid
[0] = GetSystemDefaultLCID();
817 GetLocaleInfoA(lcid
[0], LOCALE_IDEFAULTANSICODEPAGE
818 |LOCALE_NOUSEROVERRIDE
, buf
, sizeof(buf
));
825 } else if (locale
[0] == 'L' && locale
[1] == 'C' && locale
[2] == '_') {
829 locale
+= 3; /* LC_ */
830 if(!memcmp(locale
, collate
, sizeof(collate
)-1)) {
831 i
= MSVCRT_LC_COLLATE
;
832 locale
+= sizeof(collate
)-1;
833 } else if(!memcmp(locale
, ctype
, sizeof(ctype
)-1)) {
835 locale
+= sizeof(ctype
)-1;
836 } else if(!memcmp(locale
, monetary
, sizeof(monetary
)-1)) {
837 i
= MSVCRT_LC_MONETARY
;
838 locale
+= sizeof(monetary
)-1;
839 } else if(!memcmp(locale
, numeric
, sizeof(numeric
)-1)) {
840 i
= MSVCRT_LC_NUMERIC
;
841 locale
+= sizeof(numeric
)-1;
842 } else if(!memcmp(locale
, time
, sizeof(time
)-1)) {
844 locale
+= sizeof(time
)-1;
848 p
= strchr(locale
, ';');
849 if(locale
[0]=='C' && (locale
[1]==';' || locale
[1]=='\0')) {
853 memcpy(buf
, locale
, p
-locale
);
854 buf
[p
-locale
] = '\0';
855 lcid
[i
] = MSVCRT_locale_to_LCID(buf
, &cp
[i
]);
857 lcid
[i
] = MSVCRT_locale_to_LCID(locale
, &cp
[i
]);
862 if(!p
|| *(p
+1)!='L' || *(p
+2)!='C' || *(p
+3)!='_')
868 lcid
[0] = MSVCRT_locale_to_LCID(locale
, &cp
[0]);
878 loc
= MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct
));
882 loc
->locinfo
= MSVCRT_malloc(sizeof(MSVCRT_threadlocinfo
));
888 loc
->mbcinfo
= MSVCRT_malloc(sizeof(MSVCRT_threadmbcinfo
));
890 MSVCRT_free(loc
->locinfo
);
895 memset(loc
->locinfo
, 0, sizeof(MSVCRT_threadlocinfo
));
896 loc
->locinfo
->refcount
= 1;
897 loc
->mbcinfo
->refcount
= 1;
899 loc
->locinfo
->lconv
= MSVCRT_malloc(sizeof(struct MSVCRT_lconv
));
900 if(!loc
->locinfo
->lconv
) {
901 MSVCRT__free_locale(loc
);
904 memset(loc
->locinfo
->lconv
, 0, sizeof(struct MSVCRT_lconv
));
906 loc
->locinfo
->pclmap
= MSVCRT_malloc(sizeof(char[256]));
907 loc
->locinfo
->pcumap
= MSVCRT_malloc(sizeof(char[256]));
908 if(!loc
->locinfo
->pclmap
|| !loc
->locinfo
->pcumap
) {
909 MSVCRT__free_locale(loc
);
913 if(lcid
[MSVCRT_LC_COLLATE
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_COLLATE
)) {
914 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_COLLATE
], cp
[MSVCRT_LC_COLLATE
], loc
, MSVCRT_LC_COLLATE
)) {
915 MSVCRT__free_locale(loc
);
919 loc
->locinfo
->lc_collate_cp
= loc
->locinfo
->lc_id
[MSVCRT_LC_COLLATE
].wCodePage
;
921 loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
= MSVCRT__strdup("C");
923 if(lcid
[MSVCRT_LC_CTYPE
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_CTYPE
)) {
927 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_CTYPE
], cp
[MSVCRT_LC_CTYPE
], loc
, MSVCRT_LC_CTYPE
)) {
928 MSVCRT__free_locale(loc
);
932 loc
->locinfo
->lc_codepage
= loc
->locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
;
933 loc
->locinfo
->lc_clike
= 1;
934 if(!GetCPInfo(loc
->locinfo
->lc_codepage
, &cp_info
)) {
935 MSVCRT__free_locale(loc
);
938 loc
->locinfo
->mb_cur_max
= cp_info
.MaxCharSize
;
940 loc
->locinfo
->ctype1_refcount
= MSVCRT_malloc(sizeof(int));
941 loc
->locinfo
->ctype1
= MSVCRT_malloc(sizeof(short[257]));
942 if(!loc
->locinfo
->ctype1_refcount
|| !loc
->locinfo
->ctype1
) {
943 MSVCRT__free_locale(loc
);
947 *loc
->locinfo
->ctype1_refcount
= 1;
948 loc
->locinfo
->ctype1
[0] = 0;
949 loc
->locinfo
->pctype
= loc
->locinfo
->ctype1
+1;
951 buf
[1] = buf
[2] = '\0';
952 for(i
=1; i
<257; i
++) {
955 /* builtin GetStringTypeA doesn't set output to 0 on invalid input */
956 loc
->locinfo
->ctype1
[i
] = 0;
958 GetStringTypeA(lcid
[MSVCRT_LC_CTYPE
], CT_CTYPE1
, buf
,
959 1, loc
->locinfo
->ctype1
+i
);
962 for(i
=0; cp_info
.LeadByte
[i
+1]!=0; i
+=2)
963 for(j
=cp_info
.LeadByte
[i
]; j
<=cp_info
.LeadByte
[i
+1]; j
++)
964 loc
->locinfo
->ctype1
[j
+1] |= MSVCRT__LEADBYTE
;
966 loc
->locinfo
->lc_clike
= 1;
967 loc
->locinfo
->mb_cur_max
= 1;
968 loc
->locinfo
->pctype
= MSVCRT__ctype
+1;
969 loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
= MSVCRT__strdup("C");
972 for(i
=0; i
<256; i
++) {
973 if(loc
->locinfo
->pctype
[i
] & MSVCRT__LEADBYTE
)
980 if(lcid
[MSVCRT_LC_CTYPE
]) {
981 LCMapStringA(lcid
[MSVCRT_LC_CTYPE
], LCMAP_LOWERCASE
, buf
, 256,
982 (char*)loc
->locinfo
->pclmap
, 256);
983 LCMapStringA(lcid
[MSVCRT_LC_CTYPE
], LCMAP_UPPERCASE
, buf
, 256,
984 (char*)loc
->locinfo
->pcumap
, 256);
986 for(i
=0; i
<256; i
++) {
987 loc
->locinfo
->pclmap
[i
] = (i
>='A' && i
<='Z' ? i
-'A'+'a' : i
);
988 loc
->locinfo
->pcumap
[i
] = (i
>='a' && i
<='z' ? i
-'a'+'A' : i
);
992 _setmbcp_l(loc
->locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
, lcid
[MSVCRT_LC_CTYPE
], loc
->mbcinfo
);
994 if(lcid
[MSVCRT_LC_MONETARY
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_MONETARY
)) {
995 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_MONETARY
], cp
[MSVCRT_LC_MONETARY
], loc
, MSVCRT_LC_MONETARY
)) {
996 MSVCRT__free_locale(loc
);
1000 loc
->locinfo
->lconv_intl_refcount
= MSVCRT_malloc(sizeof(int));
1001 loc
->locinfo
->lconv_mon_refcount
= MSVCRT_malloc(sizeof(int));
1002 if(!loc
->locinfo
->lconv_intl_refcount
|| !loc
->locinfo
->lconv_mon_refcount
) {
1003 MSVCRT__free_locale(loc
);
1007 *loc
->locinfo
->lconv_intl_refcount
= 1;
1008 *loc
->locinfo
->lconv_mon_refcount
= 1;
1010 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SINTLSYMBOL
1011 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1012 if(i
&& (loc
->locinfo
->lconv
->int_curr_symbol
= MSVCRT_malloc(i
)))
1013 memcpy(loc
->locinfo
->lconv
->int_curr_symbol
, buf
, i
);
1015 MSVCRT__free_locale(loc
);
1019 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SCURRENCY
1020 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1021 if(i
&& (loc
->locinfo
->lconv
->currency_symbol
= MSVCRT_malloc(i
)))
1022 memcpy(loc
->locinfo
->lconv
->currency_symbol
, buf
, i
);
1024 MSVCRT__free_locale(loc
);
1028 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONDECIMALSEP
1029 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1030 if(i
&& (loc
->locinfo
->lconv
->mon_decimal_point
= MSVCRT_malloc(i
)))
1031 memcpy(loc
->locinfo
->lconv
->mon_decimal_point
, buf
, i
);
1033 MSVCRT__free_locale(loc
);
1037 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONTHOUSANDSEP
1038 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1039 if(i
&& (loc
->locinfo
->lconv
->mon_thousands_sep
= MSVCRT_malloc(i
)))
1040 memcpy(loc
->locinfo
->lconv
->mon_thousands_sep
, buf
, i
);
1042 MSVCRT__free_locale(loc
);
1046 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONGROUPING
1047 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1049 i
= i
/2 + (buf
[i
-2]=='0'?0:1);
1050 if(i
&& (loc
->locinfo
->lconv
->mon_grouping
= MSVCRT_malloc(i
))) {
1051 for(i
=0; buf
[i
+1]==';'; i
+=2)
1052 loc
->locinfo
->lconv
->mon_grouping
[i
/2] = buf
[i
]-'0';
1053 loc
->locinfo
->lconv
->mon_grouping
[i
/2] = buf
[i
]-'0';
1055 loc
->locinfo
->lconv
->mon_grouping
[i
/2+1] = 127;
1057 MSVCRT__free_locale(loc
);
1061 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SPOSITIVESIGN
1062 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1063 if(i
&& (loc
->locinfo
->lconv
->positive_sign
= MSVCRT_malloc(i
)))
1064 memcpy(loc
->locinfo
->lconv
->positive_sign
, buf
, i
);
1066 MSVCRT__free_locale(loc
);
1070 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SNEGATIVESIGN
1071 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1072 if(i
&& (loc
->locinfo
->lconv
->negative_sign
= MSVCRT_malloc(i
)))
1073 memcpy(loc
->locinfo
->lconv
->negative_sign
, buf
, i
);
1075 MSVCRT__free_locale(loc
);
1079 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IINTLCURRDIGITS
1080 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1081 loc
->locinfo
->lconv
->int_frac_digits
= atoi(buf
);
1083 MSVCRT__free_locale(loc
);
1087 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_ICURRDIGITS
1088 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1089 loc
->locinfo
->lconv
->frac_digits
= atoi(buf
);
1091 MSVCRT__free_locale(loc
);
1095 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSYMPRECEDES
1096 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1097 loc
->locinfo
->lconv
->p_cs_precedes
= atoi(buf
);
1099 MSVCRT__free_locale(loc
);
1103 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSEPBYSPACE
1104 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1105 loc
->locinfo
->lconv
->p_sep_by_space
= atoi(buf
);
1107 MSVCRT__free_locale(loc
);
1111 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSYMPRECEDES
1112 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1113 loc
->locinfo
->lconv
->n_cs_precedes
= atoi(buf
);
1115 MSVCRT__free_locale(loc
);
1119 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSEPBYSPACE
1120 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1121 loc
->locinfo
->lconv
->n_sep_by_space
= atoi(buf
);
1123 MSVCRT__free_locale(loc
);
1127 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSIGNPOSN
1128 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1129 loc
->locinfo
->lconv
->p_sign_posn
= atoi(buf
);
1131 MSVCRT__free_locale(loc
);
1135 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSIGNPOSN
1136 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1137 loc
->locinfo
->lconv
->n_sign_posn
= atoi(buf
);
1139 MSVCRT__free_locale(loc
);
1143 #if _MSVCR_VER >= 120
1144 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SINTLSYMBOL
1145 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1146 if(i
&& (loc
->locinfo
->lconv
->_W_int_curr_symbol
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1147 memcpy(loc
->locinfo
->lconv
->_W_int_curr_symbol
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1149 MSVCRT__free_locale(loc
);
1153 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SCURRENCY
1154 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1155 if(i
&& (loc
->locinfo
->lconv
->_W_currency_symbol
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1156 memcpy(loc
->locinfo
->lconv
->_W_currency_symbol
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1158 MSVCRT__free_locale(loc
);
1162 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONDECIMALSEP
1163 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1164 if(i
&& (loc
->locinfo
->lconv
->_W_mon_decimal_point
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1165 memcpy(loc
->locinfo
->lconv
->_W_mon_decimal_point
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1167 MSVCRT__free_locale(loc
);
1171 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONTHOUSANDSEP
1172 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1173 if(i
&& (loc
->locinfo
->lconv
->_W_mon_thousands_sep
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1174 memcpy(loc
->locinfo
->lconv
->_W_mon_thousands_sep
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1176 MSVCRT__free_locale(loc
);
1180 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SPOSITIVESIGN
1181 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1182 if(i
&& (loc
->locinfo
->lconv
->_W_positive_sign
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1183 memcpy(loc
->locinfo
->lconv
->_W_positive_sign
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1185 MSVCRT__free_locale(loc
);
1189 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SNEGATIVESIGN
1190 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1191 if(i
&& (loc
->locinfo
->lconv
->_W_negative_sign
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1192 memcpy(loc
->locinfo
->lconv
->_W_negative_sign
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1194 MSVCRT__free_locale(loc
);
1200 loc
->locinfo
->lconv
->int_curr_symbol
= MSVCRT_malloc(sizeof(char));
1201 loc
->locinfo
->lconv
->currency_symbol
= MSVCRT_malloc(sizeof(char));
1202 loc
->locinfo
->lconv
->mon_decimal_point
= MSVCRT_malloc(sizeof(char));
1203 loc
->locinfo
->lconv
->mon_thousands_sep
= MSVCRT_malloc(sizeof(char));
1204 loc
->locinfo
->lconv
->mon_grouping
= MSVCRT_malloc(sizeof(char));
1205 loc
->locinfo
->lconv
->positive_sign
= MSVCRT_malloc(sizeof(char));
1206 loc
->locinfo
->lconv
->negative_sign
= MSVCRT_malloc(sizeof(char));
1208 if(!loc
->locinfo
->lconv
->int_curr_symbol
|| !loc
->locinfo
->lconv
->currency_symbol
1209 || !loc
->locinfo
->lconv
->mon_decimal_point
|| !loc
->locinfo
->lconv
->mon_thousands_sep
1210 || !loc
->locinfo
->lconv
->mon_grouping
|| !loc
->locinfo
->lconv
->positive_sign
1211 || !loc
->locinfo
->lconv
->negative_sign
) {
1212 MSVCRT__free_locale(loc
);
1216 loc
->locinfo
->lconv
->int_curr_symbol
[0] = '\0';
1217 loc
->locinfo
->lconv
->currency_symbol
[0] = '\0';
1218 loc
->locinfo
->lconv
->mon_decimal_point
[0] = '\0';
1219 loc
->locinfo
->lconv
->mon_thousands_sep
[0] = '\0';
1220 loc
->locinfo
->lconv
->mon_grouping
[0] = '\0';
1221 loc
->locinfo
->lconv
->positive_sign
[0] = '\0';
1222 loc
->locinfo
->lconv
->negative_sign
[0] = '\0';
1223 loc
->locinfo
->lconv
->int_frac_digits
= 127;
1224 loc
->locinfo
->lconv
->frac_digits
= 127;
1225 loc
->locinfo
->lconv
->p_cs_precedes
= 127;
1226 loc
->locinfo
->lconv
->p_sep_by_space
= 127;
1227 loc
->locinfo
->lconv
->n_cs_precedes
= 127;
1228 loc
->locinfo
->lconv
->n_sep_by_space
= 127;
1229 loc
->locinfo
->lconv
->p_sign_posn
= 127;
1230 loc
->locinfo
->lconv
->n_sign_posn
= 127;
1232 #if _MSVCR_VER >= 120
1233 loc
->locinfo
->lconv
->_W_int_curr_symbol
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1234 loc
->locinfo
->lconv
->_W_currency_symbol
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1235 loc
->locinfo
->lconv
->_W_mon_decimal_point
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1236 loc
->locinfo
->lconv
->_W_mon_thousands_sep
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1237 loc
->locinfo
->lconv
->_W_positive_sign
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1238 loc
->locinfo
->lconv
->_W_negative_sign
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1240 if(!loc
->locinfo
->lconv
->_W_int_curr_symbol
|| !loc
->locinfo
->lconv
->_W_currency_symbol
1241 || !loc
->locinfo
->lconv
->_W_mon_decimal_point
|| !loc
->locinfo
->lconv
->_W_mon_thousands_sep
1242 || !loc
->locinfo
->lconv
->positive_sign
|| !loc
->locinfo
->lconv
->negative_sign
) {
1243 MSVCRT__free_locale(loc
);
1247 loc
->locinfo
->lconv
->_W_int_curr_symbol
[0] = '\0';
1248 loc
->locinfo
->lconv
->_W_currency_symbol
[0] = '\0';
1249 loc
->locinfo
->lconv
->_W_mon_decimal_point
[0] = '\0';
1250 loc
->locinfo
->lconv
->_W_mon_thousands_sep
[0] = '\0';
1251 loc
->locinfo
->lconv
->_W_positive_sign
[0] = '\0';
1252 loc
->locinfo
->lconv
->_W_negative_sign
[0] = '\0';
1255 loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
= MSVCRT__strdup("C");
1258 if(lcid
[MSVCRT_LC_NUMERIC
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_NUMERIC
)) {
1259 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_NUMERIC
], cp
[MSVCRT_LC_NUMERIC
], loc
, MSVCRT_LC_NUMERIC
)) {
1260 MSVCRT__free_locale(loc
);
1264 if(!loc
->locinfo
->lconv_intl_refcount
)
1265 loc
->locinfo
->lconv_intl_refcount
= MSVCRT_malloc(sizeof(int));
1266 loc
->locinfo
->lconv_num_refcount
= MSVCRT_malloc(sizeof(int));
1267 if(!loc
->locinfo
->lconv_intl_refcount
|| !loc
->locinfo
->lconv_num_refcount
) {
1268 MSVCRT__free_locale(loc
);
1272 *loc
->locinfo
->lconv_intl_refcount
= 1;
1273 *loc
->locinfo
->lconv_num_refcount
= 1;
1275 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SDECIMAL
1276 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1277 if(i
&& (loc
->locinfo
->lconv
->decimal_point
= MSVCRT_malloc(i
)))
1278 memcpy(loc
->locinfo
->lconv
->decimal_point
, buf
, i
);
1280 MSVCRT__free_locale(loc
);
1284 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_STHOUSAND
1285 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1286 if(i
&& (loc
->locinfo
->lconv
->thousands_sep
= MSVCRT_malloc(i
)))
1287 memcpy(loc
->locinfo
->lconv
->thousands_sep
, buf
, i
);
1289 MSVCRT__free_locale(loc
);
1293 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SGROUPING
1294 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1296 i
= i
/2 + (buf
[i
-2]=='0'?0:1);
1297 if(i
&& (loc
->locinfo
->lconv
->grouping
= MSVCRT_malloc(i
))) {
1298 for(i
=0; buf
[i
+1]==';'; i
+=2)
1299 loc
->locinfo
->lconv
->grouping
[i
/2] = buf
[i
]-'0';
1300 loc
->locinfo
->lconv
->grouping
[i
/2] = buf
[i
]-'0';
1302 loc
->locinfo
->lconv
->grouping
[i
/2+1] = 127;
1304 MSVCRT__free_locale(loc
);
1308 #if _MSVCR_VER >= 120
1309 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SDECIMAL
1310 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1311 if(i
&& (loc
->locinfo
->lconv
->_W_decimal_point
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1312 memcpy(loc
->locinfo
->lconv
->_W_decimal_point
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1314 MSVCRT__free_locale(loc
);
1318 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_STHOUSAND
1319 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1320 if(i
&& (loc
->locinfo
->lconv
->_W_thousands_sep
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1321 memcpy(loc
->locinfo
->lconv
->_W_thousands_sep
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1323 MSVCRT__free_locale(loc
);
1329 loc
->locinfo
->lconv
->decimal_point
= MSVCRT_malloc(sizeof(char[2]));
1330 loc
->locinfo
->lconv
->thousands_sep
= MSVCRT_malloc(sizeof(char));
1331 loc
->locinfo
->lconv
->grouping
= MSVCRT_malloc(sizeof(char));
1332 if(!loc
->locinfo
->lconv
->decimal_point
|| !loc
->locinfo
->lconv
->thousands_sep
1333 || !loc
->locinfo
->lconv
->grouping
) {
1334 MSVCRT__free_locale(loc
);
1338 loc
->locinfo
->lconv
->decimal_point
[0] = '.';
1339 loc
->locinfo
->lconv
->decimal_point
[1] = '\0';
1340 loc
->locinfo
->lconv
->thousands_sep
[0] = '\0';
1341 loc
->locinfo
->lconv
->grouping
[0] = '\0';
1343 #if _MSVCR_VER >= 120
1344 loc
->locinfo
->lconv
->_W_decimal_point
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
[2]));
1345 loc
->locinfo
->lconv
->_W_thousands_sep
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1347 if(!loc
->locinfo
->lconv
->_W_decimal_point
|| !loc
->locinfo
->lconv
->_W_thousands_sep
) {
1348 MSVCRT__free_locale(loc
);
1352 loc
->locinfo
->lconv
->_W_decimal_point
[0] = '.';
1353 loc
->locinfo
->lconv
->_W_decimal_point
[1] = '\0';
1354 loc
->locinfo
->lconv
->_W_thousands_sep
[0] = '\0';
1357 loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
= MSVCRT__strdup("C");
1360 if(lcid
[MSVCRT_LC_TIME
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_TIME
)) {
1361 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_TIME
], cp
[MSVCRT_LC_TIME
], loc
, MSVCRT_LC_TIME
)) {
1362 MSVCRT__free_locale(loc
);
1366 loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
= MSVCRT__strdup("C");
1368 size
= sizeof(MSVCRT___lc_time_data
);
1369 lcid_tmp
= lcid
[MSVCRT_LC_TIME
] ? lcid
[MSVCRT_LC_TIME
] : MAKELCID(LANG_ENGLISH
, SORT_DEFAULT
);
1370 for(i
=0; i
<sizeof(time_data
)/sizeof(time_data
[0]); i
++) {
1371 if(time_data
[i
]==LOCALE_SSHORTDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1372 size
+= sizeof(cloc_short_date
) + sizeof(cloc_short_dateW
);
1373 }else if(time_data
[i
]==LOCALE_SLONGDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1374 size
+= sizeof(cloc_long_date
) + sizeof(cloc_long_dateW
);
1376 ret
= GetLocaleInfoA(lcid_tmp
, time_data
[i
]
1377 |LOCALE_NOUSEROVERRIDE
, NULL
, 0);
1379 MSVCRT__free_locale(loc
);
1384 ret
= GetLocaleInfoW(lcid_tmp
, time_data
[i
]
1385 |LOCALE_NOUSEROVERRIDE
, NULL
, 0);
1387 MSVCRT__free_locale(loc
);
1390 size
+= ret
*sizeof(MSVCRT_wchar_t
);
1394 loc
->locinfo
->lc_time_curr
= MSVCRT_malloc(size
);
1395 if(!loc
->locinfo
->lc_time_curr
) {
1396 MSVCRT__free_locale(loc
);
1401 for(i
=0; i
<sizeof(time_data
)/sizeof(time_data
[0]); i
++) {
1402 loc
->locinfo
->lc_time_curr
->str
.str
[i
] = &loc
->locinfo
->lc_time_curr
->data
[ret
];
1403 if(time_data
[i
]==LOCALE_SSHORTDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1404 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_short_date
, sizeof(cloc_short_date
));
1405 ret
+= sizeof(cloc_short_date
);
1406 }else if(time_data
[i
]==LOCALE_SLONGDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1407 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_long_date
, sizeof(cloc_long_date
));
1408 ret
+= sizeof(cloc_long_date
);
1409 }else if(time_data
[i
]==LOCALE_STIMEFORMAT
&& !lcid
[MSVCRT_LC_TIME
]) {
1410 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_time
, sizeof(cloc_time
));
1411 ret
+= sizeof(cloc_time
);
1413 ret
+= GetLocaleInfoA(lcid_tmp
, time_data
[i
]|LOCALE_NOUSEROVERRIDE
,
1414 &loc
->locinfo
->lc_time_curr
->data
[ret
], size
-ret
);
1417 for(i
=0; i
<sizeof(time_data
)/sizeof(time_data
[0]); i
++) {
1418 loc
->locinfo
->lc_time_curr
->wstr
.wstr
[i
] = (MSVCRT_wchar_t
*)&loc
->locinfo
->lc_time_curr
->data
[ret
];
1419 if(time_data
[i
]==LOCALE_SSHORTDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1420 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_short_dateW
, sizeof(cloc_short_dateW
));
1421 ret
+= sizeof(cloc_short_dateW
);
1422 }else if(time_data
[i
]==LOCALE_SLONGDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1423 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_long_dateW
, sizeof(cloc_long_dateW
));
1424 ret
+= sizeof(cloc_long_dateW
);
1425 }else if(time_data
[i
]==LOCALE_STIMEFORMAT
&& !lcid
[MSVCRT_LC_TIME
]) {
1426 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_timeW
, sizeof(cloc_timeW
));
1427 ret
+= sizeof(cloc_timeW
);
1429 ret
+= GetLocaleInfoW(lcid_tmp
, time_data
[i
]|LOCALE_NOUSEROVERRIDE
,
1430 (MSVCRT_wchar_t
*)&loc
->locinfo
->lc_time_curr
->data
[ret
], size
-ret
)*sizeof(MSVCRT_wchar_t
);
1433 loc
->locinfo
->lc_time_curr
->lcid
= lcid
[MSVCRT_LC_TIME
];
1438 /*********************************************************************
1439 * setlocale (MSVCRT.@)
1441 char* CDECL
MSVCRT_setlocale(int category
, const char* locale
)
1443 MSVCRT__locale_t loc
;
1444 MSVCRT_pthreadlocinfo locinfo
= get_locinfo();
1446 if(category
<MSVCRT_LC_MIN
|| category
>MSVCRT_LC_MAX
)
1450 if(category
== MSVCRT_LC_ALL
)
1451 return construct_lc_all(locinfo
);
1453 return locinfo
->lc_category
[category
].locale
;
1456 loc
= MSVCRT__create_locale(category
, locale
);
1458 WARN("%d %s failed\n", category
, locale
);
1466 case MSVCRT_LC_COLLATE
:
1467 locinfo
->lc_collate_cp
= loc
->locinfo
->lc_collate_cp
;
1468 locinfo
->lc_handle
[MSVCRT_LC_COLLATE
] =
1469 loc
->locinfo
->lc_handle
[MSVCRT_LC_COLLATE
];
1470 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
,
1471 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
);
1472 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_COLLATE
].refcount
,
1473 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].refcount
);
1475 if(category
!= MSVCRT_LC_ALL
)
1478 case MSVCRT_LC_CTYPE
:
1479 locinfo
->lc_handle
[MSVCRT_LC_CTYPE
] =
1480 loc
->locinfo
->lc_handle
[MSVCRT_LC_CTYPE
];
1481 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
,
1482 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
);
1483 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_CTYPE
].refcount
,
1484 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].refcount
);
1486 locinfo
->lc_codepage
= loc
->locinfo
->lc_codepage
;
1487 locinfo
->lc_clike
= loc
->locinfo
->lc_clike
;
1488 locinfo
->mb_cur_max
= loc
->locinfo
->mb_cur_max
;
1490 swap_pointers((void**)&locinfo
->ctype1_refcount
,
1491 (void**)&loc
->locinfo
->ctype1_refcount
);
1492 swap_pointers((void**)&locinfo
->ctype1
, (void**)&loc
->locinfo
->ctype1
);
1493 swap_pointers((void**)&locinfo
->pctype
, (void**)&loc
->locinfo
->pctype
);
1494 swap_pointers((void**)&locinfo
->pclmap
, (void**)&loc
->locinfo
->pclmap
);
1495 swap_pointers((void**)&locinfo
->pcumap
, (void**)&loc
->locinfo
->pcumap
);
1497 if(category
!= MSVCRT_LC_ALL
)
1500 case MSVCRT_LC_MONETARY
:
1501 locinfo
->lc_handle
[MSVCRT_LC_MONETARY
] =
1502 loc
->locinfo
->lc_handle
[MSVCRT_LC_MONETARY
];
1503 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
,
1504 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
);
1505 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_MONETARY
].refcount
,
1506 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].refcount
);
1508 swap_pointers((void**)&locinfo
->lconv
->int_curr_symbol
,
1509 (void**)&loc
->locinfo
->lconv
->int_curr_symbol
);
1510 swap_pointers((void**)&locinfo
->lconv
->currency_symbol
,
1511 (void**)&loc
->locinfo
->lconv
->currency_symbol
);
1512 swap_pointers((void**)&locinfo
->lconv
->mon_decimal_point
,
1513 (void**)&loc
->locinfo
->lconv
->mon_decimal_point
);
1514 swap_pointers((void**)&locinfo
->lconv
->mon_thousands_sep
,
1515 (void**)&loc
->locinfo
->lconv
->mon_thousands_sep
);
1516 swap_pointers((void**)&locinfo
->lconv
->mon_grouping
,
1517 (void**)&loc
->locinfo
->lconv
->mon_grouping
);
1518 swap_pointers((void**)&locinfo
->lconv
->positive_sign
,
1519 (void**)&loc
->locinfo
->lconv
->positive_sign
);
1520 swap_pointers((void**)&locinfo
->lconv
->negative_sign
,
1521 (void**)&loc
->locinfo
->lconv
->negative_sign
);
1523 #if _MSVCR_VER >= 120
1524 swap_pointers((void**)&locinfo
->lconv
->_W_int_curr_symbol
,
1525 (void**)&loc
->locinfo
->lconv
->_W_int_curr_symbol
);
1526 swap_pointers((void**)&locinfo
->lconv
->_W_currency_symbol
,
1527 (void**)&loc
->locinfo
->lconv
->_W_currency_symbol
);
1528 swap_pointers((void**)&locinfo
->lconv
->_W_mon_decimal_point
,
1529 (void**)&loc
->locinfo
->lconv
->_W_mon_decimal_point
);
1530 swap_pointers((void**)&locinfo
->lconv
->_W_mon_thousands_sep
,
1531 (void**)&loc
->locinfo
->lconv
->_W_mon_thousands_sep
);
1532 swap_pointers((void**)&locinfo
->lconv
->_W_positive_sign
,
1533 (void**)&loc
->locinfo
->lconv
->_W_positive_sign
);
1534 swap_pointers((void**)&locinfo
->lconv
->_W_negative_sign
,
1535 (void**)&loc
->locinfo
->lconv
->_W_negative_sign
);
1538 locinfo
->lconv
->int_frac_digits
= loc
->locinfo
->lconv
->int_frac_digits
;
1539 locinfo
->lconv
->frac_digits
= loc
->locinfo
->lconv
->frac_digits
;
1540 locinfo
->lconv
->p_cs_precedes
= loc
->locinfo
->lconv
->p_cs_precedes
;
1541 locinfo
->lconv
->p_sep_by_space
= loc
->locinfo
->lconv
->p_sep_by_space
;
1542 locinfo
->lconv
->n_cs_precedes
= loc
->locinfo
->lconv
->n_cs_precedes
;
1543 locinfo
->lconv
->n_sep_by_space
= loc
->locinfo
->lconv
->n_sep_by_space
;
1544 locinfo
->lconv
->p_sign_posn
= loc
->locinfo
->lconv
->p_sign_posn
;
1545 locinfo
->lconv
->n_sign_posn
= loc
->locinfo
->lconv
->n_sign_posn
;
1547 if(category
!= MSVCRT_LC_ALL
)
1550 case MSVCRT_LC_NUMERIC
:
1551 locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
] =
1552 loc
->locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
];
1553 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
,
1554 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
);
1555 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].refcount
,
1556 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].refcount
);
1558 swap_pointers((void**)&locinfo
->lconv
->decimal_point
,
1559 (void**)&loc
->locinfo
->lconv
->decimal_point
);
1560 swap_pointers((void**)&locinfo
->lconv
->thousands_sep
,
1561 (void**)&loc
->locinfo
->lconv
->thousands_sep
);
1562 swap_pointers((void**)&locinfo
->lconv
->grouping
,
1563 (void**)&loc
->locinfo
->lconv
->grouping
);
1565 #if _MSVCR_VER >= 120
1566 swap_pointers((void**)&locinfo
->lconv
->_W_decimal_point
,
1567 (void**)&loc
->locinfo
->lconv
->_W_decimal_point
);
1568 swap_pointers((void**)&locinfo
->lconv
->_W_thousands_sep
,
1569 (void**)&loc
->locinfo
->lconv
->_W_thousands_sep
);
1572 if(category
!= MSVCRT_LC_ALL
)
1575 case MSVCRT_LC_TIME
:
1576 locinfo
->lc_handle
[MSVCRT_LC_TIME
] =
1577 loc
->locinfo
->lc_handle
[MSVCRT_LC_TIME
];
1578 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
,
1579 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
);
1580 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_TIME
].refcount
,
1581 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].refcount
);
1582 swap_pointers((void**)&locinfo
->lc_time_curr
,
1583 (void**)&loc
->locinfo
->lc_time_curr
);
1585 if(category
!= MSVCRT_LC_ALL
)
1589 MSVCRT__free_locale(loc
);
1592 if(locinfo
== MSVCRT_locale
->locinfo
) {
1595 MSVCRT___lc_codepage
= locinfo
->lc_codepage
;
1596 MSVCRT___lc_collate_cp
= locinfo
->lc_collate_cp
;
1597 MSVCRT___mb_cur_max
= locinfo
->mb_cur_max
;
1598 MSVCRT__pctype
= locinfo
->pctype
;
1599 for(i
=MSVCRT_LC_MIN
; i
<=MSVCRT_LC_MAX
; i
++)
1600 MSVCRT___lc_handle
[i
] = MSVCRT_locale
->locinfo
->lc_handle
[i
];
1603 if(category
== MSVCRT_LC_ALL
)
1604 return construct_lc_all(locinfo
);
1606 return locinfo
->lc_category
[category
].locale
;
1609 /*********************************************************************
1610 * _wsetlocale (MSVCRT.@)
1612 MSVCRT_wchar_t
* CDECL
MSVCRT__wsetlocale(int category
, const MSVCRT_wchar_t
* wlocale
)
1614 static MSVCRT_wchar_t current_lc_all
[MAX_LOCALE_LENGTH
];
1616 char *locale
= NULL
;
1621 len
= MSVCRT_wcstombs(NULL
, wlocale
, 0);
1625 locale
= MSVCRT_malloc(++len
);
1629 MSVCRT_wcstombs(locale
, wlocale
, len
);
1633 ret
= MSVCRT_setlocale(category
, locale
);
1634 MSVCRT_free(locale
);
1636 if(ret
&& MSVCRT_mbstowcs(current_lc_all
, ret
, MAX_LOCALE_LENGTH
)==-1)
1640 return ret
? current_lc_all
: NULL
;
1643 /*********************************************************************
1644 * _configthreadlocale (MSVCR80.@)
1646 int CDECL
_configthreadlocale(int type
)
1648 thread_data_t
*data
= msvcrt_get_thread_data();
1649 MSVCRT__locale_t locale
;
1655 ret
= (data
->have_locale
? MSVCRT__ENABLE_PER_THREAD_LOCALE
: MSVCRT__DISABLE_PER_THREAD_LOCALE
);
1657 if(type
== MSVCRT__ENABLE_PER_THREAD_LOCALE
) {
1658 if(!data
->have_locale
) {
1659 /* Copy current global locale */
1660 locale
= MSVCRT__create_locale(MSVCRT_LC_ALL
, MSVCRT_setlocale(MSVCRT_LC_ALL
, NULL
));
1664 data
->locinfo
= locale
->locinfo
;
1665 data
->mbcinfo
= locale
->mbcinfo
;
1666 data
->have_locale
= TRUE
;
1667 MSVCRT_free(locale
);
1673 if(type
== MSVCRT__DISABLE_PER_THREAD_LOCALE
) {
1674 if(data
->have_locale
) {
1675 free_locinfo(data
->locinfo
);
1676 free_mbcinfo(data
->mbcinfo
);
1677 data
->locinfo
= MSVCRT_locale
->locinfo
;
1678 data
->mbcinfo
= MSVCRT_locale
->mbcinfo
;
1679 data
->have_locale
= FALSE
;
1691 BOOL
msvcrt_init_locale(void)
1696 MSVCRT_locale
= MSVCRT__create_locale(0, "C");
1701 MSVCRT___lc_codepage
= MSVCRT_locale
->locinfo
->lc_codepage
;
1702 MSVCRT___lc_collate_cp
= MSVCRT_locale
->locinfo
->lc_collate_cp
;
1703 MSVCRT___mb_cur_max
= MSVCRT_locale
->locinfo
->mb_cur_max
;
1704 MSVCRT__pctype
= MSVCRT_locale
->locinfo
->pctype
;
1705 for(i
=MSVCRT_LC_MIN
; i
<=MSVCRT_LC_MAX
; i
++)
1706 MSVCRT___lc_handle
[i
] = MSVCRT_locale
->locinfo
->lc_handle
[i
];
1707 _setmbcp(_MB_CP_ANSI
);