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 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
)
134 GetLocaleInfoA(lcid
, flags
|LOCALE_NOUSEROVERRIDE
, buff
, MAX_ELEM_LEN
);
135 if (!buff
[0] || !cmp
[0])
138 /* Partial matches are only allowed on language/country names */
141 return !strcasecmp(cmp
, buff
);
143 return !strncasecmp(cmp
, buff
, len
);
147 find_best_locale_proc(HMODULE hModule
, LPCSTR type
, LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
149 locale_search_t
*res
= (locale_search_t
*)lParam
;
150 const LCID lcid
= MAKELCID(LangID
, SORT_DEFAULT
);
151 char buff
[MAX_ELEM_LEN
];
152 unsigned int flags
= 0;
154 if(PRIMARYLANGID(LangID
) == LANG_NEUTRAL
)
155 return CONTINUE_LOOKING
;
158 if (compare_info(lcid
,LOCALE_SISO639LANGNAME
,buff
,res
->search_language
, TRUE
) ||
159 compare_info(lcid
,LOCALE_SABBREVLANGNAME
,buff
,res
->search_language
, TRUE
) ||
160 compare_info(lcid
,LOCALE_SENGLANGUAGE
,buff
,res
->search_language
, FALSE
))
162 TRACE(":Found language: %s->%s\n", res
->search_language
, buff
);
163 flags
|= FOUND_LANGUAGE
;
165 else if (res
->match_flags
& FOUND_LANGUAGE
)
167 return CONTINUE_LOOKING
;
171 if (compare_info(lcid
,LOCALE_SISO3166CTRYNAME
,buff
,res
->search_country
, TRUE
) ||
172 compare_info(lcid
,LOCALE_SABBREVCTRYNAME
,buff
,res
->search_country
, TRUE
) ||
173 compare_info(lcid
,LOCALE_SENGCOUNTRY
,buff
,res
->search_country
, FALSE
))
175 TRACE("Found country:%s->%s\n", res
->search_country
, buff
);
176 flags
|= FOUND_COUNTRY
;
178 else if (res
->match_flags
& FOUND_COUNTRY
)
180 return CONTINUE_LOOKING
;
184 if (compare_info(lcid
,LOCALE_IDEFAULTCODEPAGE
,buff
,res
->search_codepage
, TRUE
) ||
185 (compare_info(lcid
,LOCALE_IDEFAULTANSICODEPAGE
,buff
,res
->search_codepage
, TRUE
)))
187 TRACE("Found codepage:%s->%s\n", res
->search_codepage
, buff
);
188 flags
|= FOUND_CODEPAGE
;
189 memcpy(res
->found_codepage
,res
->search_codepage
,MAX_ELEM_LEN
);
191 else if (res
->match_flags
& FOUND_CODEPAGE
)
193 return CONTINUE_LOOKING
;
196 if (flags
> res
->match_flags
)
198 /* Found a better match than previously */
199 res
->match_flags
= flags
;
200 res
->found_lang_id
= LangID
;
202 if ((flags
& (FOUND_LANGUAGE
| FOUND_COUNTRY
| FOUND_CODEPAGE
)) ==
203 (FOUND_LANGUAGE
| FOUND_COUNTRY
| FOUND_CODEPAGE
))
205 TRACE(":found exact locale match\n");
208 return CONTINUE_LOOKING
;
211 extern int atoi(const char *);
213 /* Internal: Find the LCID for a locale specification */
214 LCID
MSVCRT_locale_to_LCID(const char *locale
)
217 locale_search_t search
;
218 const char *cp
, *region
;
220 memset(&search
, 0, sizeof(locale_search_t
));
222 cp
= strchr(locale
, '.');
223 region
= strchr(locale
, '_');
225 lstrcpynA(search
.search_language
, locale
, MAX_ELEM_LEN
);
227 lstrcpynA(search
.search_country
, region
+1, MAX_ELEM_LEN
);
228 if(region
-locale
< MAX_ELEM_LEN
)
229 search
.search_language
[region
-locale
] = '\0';
231 search
.search_country
[0] = '\0';
234 lstrcpynA(search
.search_codepage
, cp
+1, MAX_ELEM_LEN
);
235 if(region
&& cp
-region
-1<MAX_ELEM_LEN
)
236 search
.search_country
[cp
-region
-1] = '\0';
237 if(cp
-locale
< MAX_ELEM_LEN
)
238 search
.search_language
[cp
-locale
] = '\0';
240 search
.search_codepage
[0] = '\0';
242 if(!search
.search_country
[0] && !search
.search_codepage
[0])
243 remap_synonym(search
.search_language
);
245 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), (LPSTR
)RT_STRING
,
246 (LPCSTR
)LOCALE_ILANGUAGE
,find_best_locale_proc
,
249 if (!search
.match_flags
)
252 /* If we were given something that didn't match, fail */
253 if (search
.search_country
[0] && !(search
.match_flags
& FOUND_COUNTRY
))
256 lcid
= MAKELCID(search
.found_lang_id
, SORT_DEFAULT
);
258 /* Populate partial locale, translating LCID to locale string elements */
259 if (!search
.found_codepage
[0]) {
260 /* Even if a codepage is not enumerated for a locale
261 * it can be set if valid */
262 if (search
.search_codepage
[0]) {
263 if (IsValidCodePage(atoi(search
.search_codepage
)))
264 memcpy(search
.found_codepage
,search
.search_codepage
,MAX_ELEM_LEN
);
266 /* Special codepage values: OEM & ANSI */
267 if (strcasecmp(search
.search_codepage
,"OCP")) {
268 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTCODEPAGE
,
269 search
.found_codepage
, MAX_ELEM_LEN
);
270 } else if (strcasecmp(search
.search_codepage
,"ACP")) {
271 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
,
272 search
.found_codepage
, MAX_ELEM_LEN
);
276 if (!atoi(search
.found_codepage
))
280 /* Prefer ANSI codepages if present */
281 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
,
282 search
.found_codepage
, MAX_ELEM_LEN
);
283 if (!search
.found_codepage
[0] || !atoi(search
.found_codepage
))
284 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTCODEPAGE
,
285 search
.found_codepage
, MAX_ELEM_LEN
);
292 /* INTERNAL: Set lc_handle, lc_id and lc_category in threadlocinfo struct */
293 static BOOL
update_threadlocinfo_category(LCID lcid
, MSVCRT__locale_t loc
, int category
)
298 if(GetLocaleInfoA(lcid
, LOCALE_ILANGUAGE
|LOCALE_NOUSEROVERRIDE
, buf
, 256)) {
301 loc
->locinfo
->lc_id
[category
].wLanguage
= 0;
303 loc
->locinfo
->lc_id
[category
].wLanguage
*= 16;
306 loc
->locinfo
->lc_id
[category
].wLanguage
+= *p
-'0';
308 loc
->locinfo
->lc_id
[category
].wLanguage
+= *p
-'a'+10;
313 loc
->locinfo
->lc_id
[category
].wCountry
=
314 loc
->locinfo
->lc_id
[category
].wLanguage
;
317 if(GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
318 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
319 loc
->locinfo
->lc_id
[category
].wCodePage
= atoi(buf
);
321 loc
->locinfo
->lc_handle
[category
] = lcid
;
324 len
+= GetLocaleInfoA(lcid
, LOCALE_SENGLANGUAGE
325 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
327 len
+= GetLocaleInfoA(lcid
, LOCALE_SENGCOUNTRY
328 |LOCALE_NOUSEROVERRIDE
, &buf
[len
], 256-len
);
330 len
+= GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
331 |LOCALE_NOUSEROVERRIDE
, &buf
[len
], 256-len
);
333 loc
->locinfo
->lc_category
[category
].locale
= MSVCRT_malloc(len
);
334 loc
->locinfo
->lc_category
[category
].refcount
= MSVCRT_malloc(sizeof(int));
335 if(!loc
->locinfo
->lc_category
[category
].locale
336 || !loc
->locinfo
->lc_category
[category
].refcount
) {
337 MSVCRT_free(loc
->locinfo
->lc_category
[category
].locale
);
338 MSVCRT_free(loc
->locinfo
->lc_category
[category
].refcount
);
339 loc
->locinfo
->lc_category
[category
].locale
= NULL
;
340 loc
->locinfo
->lc_category
[category
].refcount
= NULL
;
343 memcpy(loc
->locinfo
->lc_category
[category
].locale
, buf
, len
);
344 *loc
->locinfo
->lc_category
[category
].refcount
= 1;
349 /* INTERNAL: swap pointers values */
350 static inline void swap_pointers(void **p1
, void **p2
) {
358 /* INTERNAL: returns pthreadlocinfo struct */
359 MSVCRT_pthreadlocinfo
get_locinfo(void) {
360 thread_data_t
*data
= msvcrt_get_thread_data();
362 if(!data
|| !data
->have_locale
)
363 return MSVCRT_locale
->locinfo
;
365 return data
->locinfo
;
368 /* INTERNAL: returns pthreadlocinfo struct */
369 MSVCRT_pthreadmbcinfo
get_mbcinfo(void) {
370 thread_data_t
*data
= msvcrt_get_thread_data();
372 if(!data
|| !data
->have_locale
)
373 return MSVCRT_locale
->mbcinfo
;
375 return data
->mbcinfo
;
378 /* INTERNAL: constructs string returned by setlocale */
379 static inline char* construct_lc_all(MSVCRT_pthreadlocinfo locinfo
) {
380 static char current_lc_all
[MAX_LOCALE_LENGTH
];
384 for(i
=MSVCRT_LC_MIN
+1; i
<MSVCRT_LC_MAX
; i
++) {
385 if(strcmp(locinfo
->lc_category
[i
].locale
,
386 locinfo
->lc_category
[i
+1].locale
))
391 return locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
;
393 sprintf(current_lc_all
,
394 "LC_COLLATE=%s;LC_CTYPE=%s;LC_MONETARY=%s;LC_NUMERIC=%s;LC_TIME=%s",
395 locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
,
396 locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
,
397 locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
,
398 locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
,
399 locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
);
401 return current_lc_all
;
405 /*********************************************************************
406 * wsetlocale (MSVCRT.@)
408 MSVCRT_wchar_t
* CDECL
MSVCRT__wsetlocale(int category
, const MSVCRT_wchar_t
* locale
)
410 static MSVCRT_wchar_t fake
[] = {
411 'E','n','g','l','i','s','h','_','U','n','i','t','e','d',' ',
412 'S','t','a','t','e','s','.','1','2','5','2',0 };
414 FIXME("%d %s\n", category
, debugstr_w(locale
));
419 /*********************************************************************
420 * _Getdays (MSVCRT.@)
422 char* CDECL
_Getdays(void)
424 MSVCRT___lc_time_data
*cur
= get_locinfo()->lc_time_curr
;
430 size
= cur
->str
[2*7]-cur
->str
[0];
431 out
= MSVCRT_malloc(size
+1);
438 len
= strlen(cur
->str
[i
]);
439 memcpy(&out
[size
], cur
->str
[i
], len
);
443 len
= strlen(cur
->str
[7+i
]);
444 memcpy(&out
[size
], cur
->str
[7+i
], len
);
451 /*********************************************************************
452 * _Getmonths (MSVCRT.@)
454 char* CDECL
_Getmonths(void)
456 static const int months_offset
= 14;
458 MSVCRT___lc_time_data
*cur
= get_locinfo()->lc_time_curr
;
464 size
= cur
->str
[months_offset
+2*12]-cur
->str
[months_offset
];
465 out
= MSVCRT_malloc(size
+1);
470 for(i
=0; i
<12; i
++) {
472 len
= strlen(cur
->str
[months_offset
+i
]);
473 memcpy(&out
[size
], cur
->str
[months_offset
+i
], len
);
477 len
= strlen(cur
->str
[months_offset
+12+i
]);
478 memcpy(&out
[size
], cur
->str
[months_offset
+12+i
], len
);
485 /*********************************************************************
486 * _Gettnames (MSVCRT.@)
488 void* CDECL
_Gettnames(void)
490 MSVCRT___lc_time_data
*ret
, *cur
= get_locinfo()->lc_time_curr
;
491 int i
, size
= sizeof(MSVCRT___lc_time_data
);
495 for(i
=0; i
<sizeof(cur
->str
)/sizeof(cur
->str
[0]); i
++)
496 size
+= strlen(cur
->str
[i
])+1;
498 ret
= MSVCRT_malloc(size
);
501 memcpy(ret
, cur
, size
);
504 for(i
=0; i
<sizeof(cur
->str
)/sizeof(cur
->str
[0]); i
++) {
505 ret
->str
[i
] = &ret
->data
[size
];
506 size
+= strlen(&ret
->data
[size
])+1;
512 /*********************************************************************
513 * _Strftime (MSVCRT.@)
515 const char* CDECL
_Strftime(char *out
, unsigned int len
, const char *fmt
,
516 const void *tm
, void *foo
)
519 TRACE("(%p %d %s %p %p) stub\n", out
, len
, fmt
, tm
, foo
);
523 /*********************************************************************
524 * __crtLCMapStringA (MSVCRT.@)
526 int CDECL
__crtLCMapStringA(
527 LCID lcid
, DWORD mapflags
, const char* src
, int srclen
, char* dst
,
528 int dstlen
, unsigned int codepage
, int xflag
530 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
531 lcid
,mapflags
,src
,srclen
,dst
,dstlen
,codepage
,xflag
);
532 /* FIXME: A bit incorrect. But msvcrt itself just converts its
533 * arguments to wide strings and then calls LCMapStringW
535 return LCMapStringA(lcid
,mapflags
,src
,srclen
,dst
,dstlen
);
538 /*********************************************************************
539 * __crtLCMapStringW (MSVCRT.@)
541 int CDECL
__crtLCMapStringW(LCID lcid
, DWORD mapflags
, const MSVCRT_wchar_t
*src
,
542 int srclen
, MSVCRT_wchar_t
*dst
, int dstlen
, unsigned int codepage
, int xflag
)
544 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
545 lcid
, mapflags
, debugstr_w(src
), srclen
, dst
, dstlen
, codepage
, xflag
);
547 return LCMapStringW(lcid
, mapflags
, src
, srclen
, dst
, dstlen
);
550 /*********************************************************************
551 * __crtCompareStringA (MSVCRT.@)
553 int CDECL
__crtCompareStringA( LCID lcid
, DWORD flags
, const char *src1
, int len1
,
554 const char *src2
, int len2
)
556 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
557 lcid
, flags
, debugstr_a(src1
), len1
, debugstr_a(src2
), len2
);
558 /* FIXME: probably not entirely right */
559 return CompareStringA( lcid
, flags
, src1
, len1
, src2
, len2
);
562 /*********************************************************************
563 * __crtCompareStringW (MSVCRT.@)
565 int CDECL
__crtCompareStringW( LCID lcid
, DWORD flags
, const MSVCRT_wchar_t
*src1
, int len1
,
566 const MSVCRT_wchar_t
*src2
, int len2
)
568 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
569 lcid
, flags
, debugstr_w(src1
), len1
, debugstr_w(src2
), len2
);
570 /* FIXME: probably not entirely right */
571 return CompareStringW( lcid
, flags
, src1
, len1
, src2
, len2
);
574 /*********************************************************************
575 * __crtGetLocaleInfoW (MSVCRT.@)
577 int CDECL
__crtGetLocaleInfoW( LCID lcid
, LCTYPE type
, MSVCRT_wchar_t
*buffer
, int len
)
579 FIXME("(lcid %x, type %x, %p(%d), partial stub\n", lcid
, type
, buffer
, len
);
580 /* FIXME: probably not entirely right */
581 return GetLocaleInfoW( lcid
, type
, buffer
, len
);
584 /*********************************************************************
587 MSVCRT_wint_t CDECL
MSVCRT_btowc(int c
)
589 unsigned char letter
= c
;
592 if(!MultiByteToWideChar(get_locinfo()->lc_handle
[MSVCRT_LC_CTYPE
],
593 0, (LPCSTR
)&letter
, 1, &ret
, 1))
599 /*********************************************************************
600 * __crtGetStringTypeW(MSVCRT.@)
602 * This function was accepting different number of arguments in older
603 * versions of msvcrt.
605 BOOL CDECL
__crtGetStringTypeW(DWORD unk
, DWORD type
,
606 MSVCRT_wchar_t
*buffer
, int len
, WORD
*out
)
608 FIXME("(unk %x, type %x, wstr %p(%d), %p) partial stub\n",
609 unk
, type
, buffer
, len
, out
);
611 return GetStringTypeW(type
, buffer
, len
, out
);
614 /*********************************************************************
615 * localeconv (MSVCRT.@)
617 struct MSVCRT_lconv
* CDECL
MSVCRT_localeconv(void)
619 return get_locinfo()->lconv
;
622 /*********************************************************************
623 * __lconv_init (MSVCRT.@)
625 int CDECL
__lconv_init(void)
627 /* this is used to make chars unsigned */
632 /*********************************************************************
633 * ___lc_handle_func (MSVCRT.@)
635 LCID
* CDECL
___lc_handle_func(void)
637 return MSVCRT___lc_handle
;
640 /*********************************************************************
641 * ___lc_codepage_func (MSVCRT.@)
643 int CDECL
___lc_codepage_func(void)
645 return MSVCRT___lc_codepage
;
648 /*********************************************************************
649 * ___lc_collate_cp_func (MSVCRT.@)
651 int CDECL
___lc_collate_cp_func(void)
653 return get_locinfo()->lc_collate_cp
;
656 /* INTERNAL: frees MSVCRT_pthreadlocinfo struct */
657 void free_locinfo(MSVCRT_pthreadlocinfo locinfo
)
664 if(InterlockedDecrement(&locinfo
->refcount
))
667 for(i
=MSVCRT_LC_MIN
+1; i
<=MSVCRT_LC_MAX
; i
++) {
668 MSVCRT_free(locinfo
->lc_category
[i
].locale
);
669 MSVCRT_free(locinfo
->lc_category
[i
].refcount
);
673 MSVCRT_free(locinfo
->lconv
->decimal_point
);
674 MSVCRT_free(locinfo
->lconv
->thousands_sep
);
675 MSVCRT_free(locinfo
->lconv
->grouping
);
676 MSVCRT_free(locinfo
->lconv
->int_curr_symbol
);
677 MSVCRT_free(locinfo
->lconv
->currency_symbol
);
678 MSVCRT_free(locinfo
->lconv
->mon_decimal_point
);
679 MSVCRT_free(locinfo
->lconv
->mon_thousands_sep
);
680 MSVCRT_free(locinfo
->lconv
->mon_grouping
);
681 MSVCRT_free(locinfo
->lconv
->positive_sign
);
682 MSVCRT_free(locinfo
->lconv
->negative_sign
);
684 MSVCRT_free(locinfo
->lconv_intl_refcount
);
685 MSVCRT_free(locinfo
->lconv_num_refcount
);
686 MSVCRT_free(locinfo
->lconv_mon_refcount
);
687 MSVCRT_free(locinfo
->lconv
);
689 MSVCRT_free(locinfo
->ctype1_refcount
);
690 MSVCRT_free(locinfo
->ctype1
);
692 MSVCRT_free(locinfo
->pclmap
);
693 MSVCRT_free(locinfo
->pcumap
);
695 MSVCRT_free(locinfo
->lc_time_curr
);
697 MSVCRT_free(locinfo
);
700 /* INTERNAL: frees MSVCRT_pthreadmbcinfo struct */
701 void free_mbcinfo(MSVCRT_pthreadmbcinfo mbcinfo
)
706 if(InterlockedDecrement(&mbcinfo
->refcount
))
709 MSVCRT_free(mbcinfo
);
712 /* _get_current_locale - not exported in native msvcrt */
713 MSVCRT__locale_t CDECL
MSVCRT__get_current_locale(void)
715 MSVCRT__locale_t loc
= MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct
));
719 loc
->locinfo
= get_locinfo();
720 loc
->mbcinfo
= get_mbcinfo();
721 InterlockedIncrement(&loc
->locinfo
->refcount
);
722 InterlockedIncrement(&loc
->mbcinfo
->refcount
);
726 /* _free_locale - not exported in native msvcrt */
727 void CDECL
MSVCRT__free_locale(MSVCRT__locale_t locale
)
732 free_locinfo(locale
->locinfo
);
733 free_mbcinfo(locale
->mbcinfo
);
737 /* _create_locale - not exported in native msvcrt */
738 MSVCRT__locale_t CDECL
MSVCRT__create_locale(int category
, const char *locale
)
740 static const DWORD time_data
[] = {
741 LOCALE_SABBREVDAYNAME7
, LOCALE_SABBREVDAYNAME1
, LOCALE_SABBREVDAYNAME2
,
742 LOCALE_SABBREVDAYNAME3
, LOCALE_SABBREVDAYNAME4
, LOCALE_SABBREVDAYNAME5
,
743 LOCALE_SABBREVDAYNAME6
,
744 LOCALE_SDAYNAME7
, LOCALE_SDAYNAME1
, LOCALE_SDAYNAME2
, LOCALE_SDAYNAME3
,
745 LOCALE_SDAYNAME4
, LOCALE_SDAYNAME5
, LOCALE_SDAYNAME6
,
746 LOCALE_SABBREVMONTHNAME1
, LOCALE_SABBREVMONTHNAME2
, LOCALE_SABBREVMONTHNAME3
,
747 LOCALE_SABBREVMONTHNAME4
, LOCALE_SABBREVMONTHNAME5
, LOCALE_SABBREVMONTHNAME6
,
748 LOCALE_SABBREVMONTHNAME7
, LOCALE_SABBREVMONTHNAME8
, LOCALE_SABBREVMONTHNAME9
,
749 LOCALE_SABBREVMONTHNAME10
, LOCALE_SABBREVMONTHNAME11
, LOCALE_SABBREVMONTHNAME12
,
750 LOCALE_SMONTHNAME1
, LOCALE_SMONTHNAME2
, LOCALE_SMONTHNAME3
, LOCALE_SMONTHNAME4
,
751 LOCALE_SMONTHNAME5
, LOCALE_SMONTHNAME6
, LOCALE_SMONTHNAME7
, LOCALE_SMONTHNAME8
,
752 LOCALE_SMONTHNAME9
, LOCALE_SMONTHNAME10
, LOCALE_SMONTHNAME11
, LOCALE_SMONTHNAME12
,
753 LOCALE_S1159
, LOCALE_S2359
,
754 LOCALE_SSHORTDATE
, LOCALE_SLONGDATE
,
757 static const char collate
[] = "COLLATE=";
758 static const char ctype
[] = "CTYPE=";
759 static const char monetary
[] = "MONETARY=";
760 static const char numeric
[] = "NUMERIC=";
761 static const char time
[] = "TIME=";
763 MSVCRT__locale_t loc
;
764 LCID lcid
[6] = { 0 };
768 TRACE("(%d %s)\n", category
, locale
);
770 if(category
<MSVCRT_LC_MIN
|| category
>MSVCRT_LC_MAX
|| !locale
)
773 if(locale
[0]=='C' && !locale
[1])
776 lcid
[0] = GetSystemDefaultLCID();
777 else if (locale
[0] == 'L' && locale
[1] == 'C' && locale
[2] == '_') {
781 locale
+= 3; /* LC_ */
782 if(!memcmp(locale
, collate
, sizeof(collate
)-1)) {
783 i
= MSVCRT_LC_COLLATE
;
784 locale
+= sizeof(collate
)-1;
785 } else if(!memcmp(locale
, ctype
, sizeof(ctype
)-1)) {
787 locale
+= sizeof(ctype
)-1;
788 } else if(!memcmp(locale
, monetary
, sizeof(monetary
)-1)) {
789 i
= MSVCRT_LC_MONETARY
;
790 locale
+= sizeof(monetary
)-1;
791 } else if(!memcmp(locale
, numeric
, sizeof(numeric
)-1)) {
792 i
= MSVCRT_LC_NUMERIC
;
793 locale
+= sizeof(numeric
)-1;
794 } else if(!memcmp(locale
, time
, sizeof(time
)-1)) {
796 locale
+= sizeof(time
)-1;
800 p
= strchr(locale
, ';');
801 if(locale
[0]=='C' && (locale
[1]==';' || locale
[1]=='\0'))
804 memcpy(buf
, locale
, p
-locale
);
805 buf
[p
-locale
] = '\0';
806 lcid
[i
] = MSVCRT_locale_to_LCID(buf
);
808 lcid
[i
] = MSVCRT_locale_to_LCID(locale
);
813 if(!p
|| *(p
+1)!='L' || *(p
+2)!='C' || *(p
+3)!='_')
819 lcid
[0] = MSVCRT_locale_to_LCID(locale
);
829 loc
= MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct
));
833 loc
->locinfo
= MSVCRT_malloc(sizeof(MSVCRT_threadlocinfo
));
839 loc
->mbcinfo
= MSVCRT_malloc(sizeof(MSVCRT_threadmbcinfo
));
841 MSVCRT_free(loc
->locinfo
);
846 memset(loc
->locinfo
, 0, sizeof(MSVCRT_threadlocinfo
));
847 loc
->locinfo
->refcount
= 1;
848 loc
->mbcinfo
->refcount
= 1;
850 loc
->locinfo
->lconv
= MSVCRT_malloc(sizeof(struct MSVCRT_lconv
));
851 if(!loc
->locinfo
->lconv
) {
852 MSVCRT__free_locale(loc
);
855 memset(loc
->locinfo
->lconv
, 0, sizeof(struct MSVCRT_lconv
));
857 loc
->locinfo
->pclmap
= MSVCRT_malloc(sizeof(char[256]));
858 loc
->locinfo
->pcumap
= MSVCRT_malloc(sizeof(char[256]));
859 if(!loc
->locinfo
->pclmap
|| !loc
->locinfo
->pcumap
) {
860 MSVCRT__free_locale(loc
);
864 if(lcid
[MSVCRT_LC_COLLATE
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_COLLATE
)) {
865 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_COLLATE
], loc
, MSVCRT_LC_COLLATE
)) {
866 MSVCRT__free_locale(loc
);
870 loc
->locinfo
->lc_collate_cp
= loc
->locinfo
->lc_id
[MSVCRT_LC_COLLATE
].wCodePage
;
872 loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
= MSVCRT__strdup("C");
874 if(lcid
[MSVCRT_LC_CTYPE
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_CTYPE
)) {
878 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_CTYPE
], loc
, MSVCRT_LC_CTYPE
)) {
879 MSVCRT__free_locale(loc
);
883 loc
->locinfo
->lc_codepage
= loc
->locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
;
884 loc
->locinfo
->lc_clike
= 1;
885 if(!GetCPInfo(loc
->locinfo
->lc_codepage
, &cp
)) {
886 MSVCRT__free_locale(loc
);
889 loc
->locinfo
->mb_cur_max
= cp
.MaxCharSize
;
891 loc
->locinfo
->ctype1_refcount
= MSVCRT_malloc(sizeof(int));
892 loc
->locinfo
->ctype1
= MSVCRT_malloc(sizeof(short[257]));
893 if(!loc
->locinfo
->ctype1_refcount
|| !loc
->locinfo
->ctype1
) {
894 MSVCRT__free_locale(loc
);
898 *loc
->locinfo
->ctype1_refcount
= 1;
899 loc
->locinfo
->ctype1
[0] = 0;
900 loc
->locinfo
->pctype
= loc
->locinfo
->ctype1
+1;
902 buf
[1] = buf
[2] = '\0';
903 for(i
=1; i
<257; i
++) {
906 /* builtin GetStringTypeA doesn't set output to 0 on invalid input */
907 loc
->locinfo
->ctype1
[i
] = 0;
909 GetStringTypeA(lcid
[MSVCRT_LC_CTYPE
], CT_CTYPE1
, buf
,
910 1, loc
->locinfo
->ctype1
+i
);
913 for(i
=0; cp
.LeadByte
[i
+1]!=0; i
+=2)
914 for(j
=cp
.LeadByte
[i
]; j
<=cp
.LeadByte
[i
+1]; j
++)
915 loc
->locinfo
->ctype1
[j
+1] |= MSVCRT__LEADBYTE
;
917 loc
->locinfo
->lc_clike
= 1;
918 loc
->locinfo
->mb_cur_max
= 1;
919 loc
->locinfo
->pctype
= MSVCRT__ctype
+1;
920 loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
= MSVCRT__strdup("C");
923 for(i
=0; i
<256; i
++) {
924 if(loc
->locinfo
->pctype
[i
] & MSVCRT__LEADBYTE
)
931 if(lcid
[MSVCRT_LC_CTYPE
]) {
932 LCMapStringA(lcid
[MSVCRT_LC_CTYPE
], LCMAP_LOWERCASE
, buf
, 256,
933 (char*)loc
->locinfo
->pclmap
, 256);
934 LCMapStringA(lcid
[MSVCRT_LC_CTYPE
], LCMAP_UPPERCASE
, buf
, 256,
935 (char*)loc
->locinfo
->pcumap
, 256);
937 for(i
=0; i
<256; i
++) {
938 loc
->locinfo
->pclmap
[i
] = (i
>='A' && i
<='Z' ? i
-'A'+'a' : i
);
939 loc
->locinfo
->pcumap
[i
] = (i
>='a' && i
<='z' ? i
-'a'+'A' : i
);
943 _setmbcp_l(loc
->locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
, lcid
[MSVCRT_LC_CTYPE
], loc
->mbcinfo
);
945 if(lcid
[MSVCRT_LC_MONETARY
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_MONETARY
)) {
946 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_MONETARY
], loc
, MSVCRT_LC_MONETARY
)) {
947 MSVCRT__free_locale(loc
);
951 loc
->locinfo
->lconv_intl_refcount
= MSVCRT_malloc(sizeof(int));
952 loc
->locinfo
->lconv_mon_refcount
= MSVCRT_malloc(sizeof(int));
953 if(!loc
->locinfo
->lconv_intl_refcount
|| !loc
->locinfo
->lconv_mon_refcount
) {
954 MSVCRT__free_locale(loc
);
958 *loc
->locinfo
->lconv_intl_refcount
= 1;
959 *loc
->locinfo
->lconv_mon_refcount
= 1;
961 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SINTLSYMBOL
962 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
963 if(i
&& (loc
->locinfo
->lconv
->int_curr_symbol
= MSVCRT_malloc(i
)))
964 memcpy(loc
->locinfo
->lconv
->int_curr_symbol
, buf
, i
);
966 MSVCRT__free_locale(loc
);
970 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SCURRENCY
971 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
972 if(i
&& (loc
->locinfo
->lconv
->currency_symbol
= MSVCRT_malloc(i
)))
973 memcpy(loc
->locinfo
->lconv
->currency_symbol
, buf
, i
);
975 MSVCRT__free_locale(loc
);
979 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONDECIMALSEP
980 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
981 if(i
&& (loc
->locinfo
->lconv
->mon_decimal_point
= MSVCRT_malloc(i
)))
982 memcpy(loc
->locinfo
->lconv
->mon_decimal_point
, buf
, i
);
984 MSVCRT__free_locale(loc
);
988 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONTHOUSANDSEP
989 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
990 if(i
&& (loc
->locinfo
->lconv
->mon_thousands_sep
= MSVCRT_malloc(i
)))
991 memcpy(loc
->locinfo
->lconv
->mon_thousands_sep
, buf
, i
);
993 MSVCRT__free_locale(loc
);
997 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONGROUPING
998 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1000 i
= i
/2 + (buf
[i
-2]=='0'?0:1);
1001 if(i
&& (loc
->locinfo
->lconv
->mon_grouping
= MSVCRT_malloc(i
))) {
1002 for(i
=0; buf
[i
+1]==';'; i
+=2)
1003 loc
->locinfo
->lconv
->mon_grouping
[i
/2] = buf
[i
]-'0';
1004 loc
->locinfo
->lconv
->mon_grouping
[i
/2] = buf
[i
]-'0';
1006 loc
->locinfo
->lconv
->mon_grouping
[i
/2+1] = 127;
1008 MSVCRT__free_locale(loc
);
1012 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SPOSITIVESIGN
1013 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1014 if(i
&& (loc
->locinfo
->lconv
->positive_sign
= MSVCRT_malloc(i
)))
1015 memcpy(loc
->locinfo
->lconv
->positive_sign
, buf
, i
);
1017 MSVCRT__free_locale(loc
);
1021 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SNEGATIVESIGN
1022 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1023 if(i
&& (loc
->locinfo
->lconv
->negative_sign
= MSVCRT_malloc(i
)))
1024 memcpy(loc
->locinfo
->lconv
->negative_sign
, buf
, i
);
1026 MSVCRT__free_locale(loc
);
1030 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IINTLCURRDIGITS
1031 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1032 loc
->locinfo
->lconv
->int_frac_digits
= atoi(buf
);
1034 MSVCRT__free_locale(loc
);
1038 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_ICURRDIGITS
1039 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1040 loc
->locinfo
->lconv
->frac_digits
= atoi(buf
);
1042 MSVCRT__free_locale(loc
);
1046 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSYMPRECEDES
1047 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1048 loc
->locinfo
->lconv
->p_cs_precedes
= atoi(buf
);
1050 MSVCRT__free_locale(loc
);
1054 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSEPBYSPACE
1055 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1056 loc
->locinfo
->lconv
->p_sep_by_space
= atoi(buf
);
1058 MSVCRT__free_locale(loc
);
1062 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSYMPRECEDES
1063 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1064 loc
->locinfo
->lconv
->n_cs_precedes
= atoi(buf
);
1066 MSVCRT__free_locale(loc
);
1070 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSEPBYSPACE
1071 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1072 loc
->locinfo
->lconv
->n_sep_by_space
= atoi(buf
);
1074 MSVCRT__free_locale(loc
);
1078 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSIGNPOSN
1079 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1080 loc
->locinfo
->lconv
->p_sign_posn
= atoi(buf
);
1082 MSVCRT__free_locale(loc
);
1086 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSIGNPOSN
1087 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1088 loc
->locinfo
->lconv
->n_sign_posn
= atoi(buf
);
1090 MSVCRT__free_locale(loc
);
1094 loc
->locinfo
->lconv
->int_curr_symbol
= MSVCRT_malloc(sizeof(char));
1095 loc
->locinfo
->lconv
->currency_symbol
= MSVCRT_malloc(sizeof(char));
1096 loc
->locinfo
->lconv
->mon_decimal_point
= MSVCRT_malloc(sizeof(char));
1097 loc
->locinfo
->lconv
->mon_thousands_sep
= MSVCRT_malloc(sizeof(char));
1098 loc
->locinfo
->lconv
->mon_grouping
= MSVCRT_malloc(sizeof(char));
1099 loc
->locinfo
->lconv
->positive_sign
= MSVCRT_malloc(sizeof(char));
1100 loc
->locinfo
->lconv
->negative_sign
= MSVCRT_malloc(sizeof(char));
1102 if(!loc
->locinfo
->lconv
->int_curr_symbol
|| !loc
->locinfo
->lconv
->currency_symbol
1103 || !loc
->locinfo
->lconv
->mon_decimal_point
|| !loc
->locinfo
->lconv
->mon_thousands_sep
1104 || !loc
->locinfo
->lconv
->mon_grouping
|| !loc
->locinfo
->lconv
->positive_sign
1105 || !loc
->locinfo
->lconv
->negative_sign
) {
1106 MSVCRT__free_locale(loc
);
1110 loc
->locinfo
->lconv
->int_curr_symbol
[0] = '\0';
1111 loc
->locinfo
->lconv
->currency_symbol
[0] = '\0';
1112 loc
->locinfo
->lconv
->mon_decimal_point
[0] = '\0';
1113 loc
->locinfo
->lconv
->mon_thousands_sep
[0] = '\0';
1114 loc
->locinfo
->lconv
->mon_grouping
[0] = '\0';
1115 loc
->locinfo
->lconv
->positive_sign
[0] = '\0';
1116 loc
->locinfo
->lconv
->negative_sign
[0] = '\0';
1117 loc
->locinfo
->lconv
->int_frac_digits
= 127;
1118 loc
->locinfo
->lconv
->frac_digits
= 127;
1119 loc
->locinfo
->lconv
->p_cs_precedes
= 127;
1120 loc
->locinfo
->lconv
->p_sep_by_space
= 127;
1121 loc
->locinfo
->lconv
->n_cs_precedes
= 127;
1122 loc
->locinfo
->lconv
->n_sep_by_space
= 127;
1123 loc
->locinfo
->lconv
->p_sign_posn
= 127;
1124 loc
->locinfo
->lconv
->n_sign_posn
= 127;
1126 loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
= MSVCRT__strdup("C");
1129 if(lcid
[MSVCRT_LC_NUMERIC
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_NUMERIC
)) {
1130 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_NUMERIC
], loc
, MSVCRT_LC_NUMERIC
)) {
1131 MSVCRT__free_locale(loc
);
1135 if(!loc
->locinfo
->lconv_intl_refcount
)
1136 loc
->locinfo
->lconv_intl_refcount
= MSVCRT_malloc(sizeof(int));
1137 loc
->locinfo
->lconv_num_refcount
= MSVCRT_malloc(sizeof(int));
1138 if(!loc
->locinfo
->lconv_intl_refcount
|| !loc
->locinfo
->lconv_num_refcount
) {
1139 MSVCRT__free_locale(loc
);
1143 *loc
->locinfo
->lconv_intl_refcount
= 1;
1144 *loc
->locinfo
->lconv_num_refcount
= 1;
1146 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SDECIMAL
1147 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1148 if(i
&& (loc
->locinfo
->lconv
->decimal_point
= MSVCRT_malloc(i
)))
1149 memcpy(loc
->locinfo
->lconv
->decimal_point
, buf
, i
);
1151 MSVCRT__free_locale(loc
);
1155 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_STHOUSAND
1156 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1157 if(i
&& (loc
->locinfo
->lconv
->thousands_sep
= MSVCRT_malloc(i
)))
1158 memcpy(loc
->locinfo
->lconv
->thousands_sep
, buf
, i
);
1160 MSVCRT__free_locale(loc
);
1164 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SGROUPING
1165 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1167 i
= i
/2 + (buf
[i
-2]=='0'?0:1);
1168 if(i
&& (loc
->locinfo
->lconv
->grouping
= MSVCRT_malloc(i
))) {
1169 for(i
=0; buf
[i
+1]==';'; i
+=2)
1170 loc
->locinfo
->lconv
->grouping
[i
/2] = buf
[i
]-'0';
1171 loc
->locinfo
->lconv
->grouping
[i
/2] = buf
[i
]-'0';
1173 loc
->locinfo
->lconv
->grouping
[i
/2+1] = 127;
1175 MSVCRT__free_locale(loc
);
1179 loc
->locinfo
->lconv
->decimal_point
= MSVCRT_malloc(sizeof(char[2]));
1180 loc
->locinfo
->lconv
->thousands_sep
= MSVCRT_malloc(sizeof(char));
1181 loc
->locinfo
->lconv
->grouping
= MSVCRT_malloc(sizeof(char));
1182 if(!loc
->locinfo
->lconv
->decimal_point
|| !loc
->locinfo
->lconv
->thousands_sep
1183 || !loc
->locinfo
->lconv
->grouping
) {
1184 MSVCRT__free_locale(loc
);
1188 loc
->locinfo
->lconv
->decimal_point
[0] = '.';
1189 loc
->locinfo
->lconv
->decimal_point
[1] = '\0';
1190 loc
->locinfo
->lconv
->thousands_sep
[0] = '\0';
1191 loc
->locinfo
->lconv
->grouping
[0] = '\0';
1193 loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
= MSVCRT__strdup("C");
1196 if(lcid
[MSVCRT_LC_TIME
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_TIME
)) {
1197 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_TIME
], loc
, MSVCRT_LC_TIME
)) {
1198 MSVCRT__free_locale(loc
);
1202 loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
= MSVCRT__strdup("C");
1204 size
= sizeof(MSVCRT___lc_time_data
);
1205 for(i
=0; i
<sizeof(time_data
)/sizeof(time_data
[0]); i
++) {
1206 ret
= GetLocaleInfoA(lcid
[MSVCRT_LC_TIME
], time_data
[i
]
1207 |LOCALE_NOUSEROVERRIDE
, NULL
, 0);
1209 MSVCRT__free_locale(loc
);
1214 ret
= GetLocaleInfoW(lcid
[MSVCRT_LC_TIME
], time_data
[i
]
1215 |LOCALE_NOUSEROVERRIDE
, NULL
, 0);
1217 MSVCRT__free_locale(loc
);
1220 size
+= ret
*sizeof(MSVCRT_wchar_t
);
1223 loc
->locinfo
->lc_time_curr
= MSVCRT_malloc(size
);
1224 if(!loc
->locinfo
->lc_time_curr
) {
1225 MSVCRT__free_locale(loc
);
1230 for(i
=0; i
<sizeof(time_data
)/sizeof(time_data
[0]); i
++) {
1231 loc
->locinfo
->lc_time_curr
->str
[i
] = &loc
->locinfo
->lc_time_curr
->data
[ret
];
1232 ret
+= GetLocaleInfoA(lcid
[MSVCRT_LC_TIME
], time_data
[i
]|LOCALE_NOUSEROVERRIDE
,
1233 &loc
->locinfo
->lc_time_curr
->data
[ret
], size
-ret
);
1235 for(i
=0; i
<sizeof(time_data
)/sizeof(time_data
[0]); i
++) {
1236 loc
->locinfo
->lc_time_curr
->wstr
[i
] = (MSVCRT_wchar_t
*)&loc
->locinfo
->lc_time_curr
->data
[ret
];
1237 ret
+= GetLocaleInfoW(lcid
[MSVCRT_LC_TIME
], time_data
[i
]|LOCALE_NOUSEROVERRIDE
,
1238 (MSVCRT_wchar_t
*)&loc
->locinfo
->lc_time_curr
->data
[ret
], size
-ret
)*sizeof(MSVCRT_wchar_t
);
1240 loc
->locinfo
->lc_time_curr
->lcid
= lcid
[MSVCRT_LC_TIME
];
1245 /*********************************************************************
1246 * setlocale (MSVCRT.@)
1248 char* CDECL
MSVCRT_setlocale(int category
, const char* locale
)
1250 MSVCRT__locale_t loc
;
1251 MSVCRT_pthreadlocinfo locinfo
= get_locinfo();
1253 if(category
<MSVCRT_LC_MIN
|| category
>MSVCRT_LC_MAX
)
1257 if(category
== MSVCRT_LC_ALL
)
1258 return construct_lc_all(locinfo
);
1260 return locinfo
->lc_category
[category
].locale
;
1263 loc
= MSVCRT__create_locale(category
, locale
);
1265 WARN("%d %s failed\n", category
, locale
);
1273 case MSVCRT_LC_COLLATE
:
1274 locinfo
->lc_collate_cp
= loc
->locinfo
->lc_collate_cp
;
1275 locinfo
->lc_handle
[MSVCRT_LC_COLLATE
] =
1276 loc
->locinfo
->lc_handle
[MSVCRT_LC_COLLATE
];
1277 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
,
1278 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
);
1279 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_COLLATE
].refcount
,
1280 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].refcount
);
1282 if(category
!= MSVCRT_LC_ALL
)
1285 case MSVCRT_LC_CTYPE
:
1286 locinfo
->lc_handle
[MSVCRT_LC_CTYPE
] =
1287 loc
->locinfo
->lc_handle
[MSVCRT_LC_CTYPE
];
1288 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
,
1289 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
);
1290 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_CTYPE
].refcount
,
1291 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].refcount
);
1293 locinfo
->lc_codepage
= loc
->locinfo
->lc_codepage
;
1294 locinfo
->lc_clike
= loc
->locinfo
->lc_clike
;
1295 locinfo
->mb_cur_max
= loc
->locinfo
->mb_cur_max
;
1297 swap_pointers((void**)&locinfo
->ctype1_refcount
,
1298 (void**)&loc
->locinfo
->ctype1_refcount
);
1299 swap_pointers((void**)&locinfo
->ctype1
, (void**)&loc
->locinfo
->ctype1
);
1300 swap_pointers((void**)&locinfo
->pctype
, (void**)&loc
->locinfo
->pctype
);
1301 swap_pointers((void**)&locinfo
->pclmap
, (void**)&loc
->locinfo
->pclmap
);
1302 swap_pointers((void**)&locinfo
->pcumap
, (void**)&loc
->locinfo
->pcumap
);
1304 if(category
!= MSVCRT_LC_ALL
)
1307 case MSVCRT_LC_MONETARY
:
1308 locinfo
->lc_handle
[MSVCRT_LC_MONETARY
] =
1309 loc
->locinfo
->lc_handle
[MSVCRT_LC_MONETARY
];
1310 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
,
1311 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
);
1312 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_MONETARY
].refcount
,
1313 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].refcount
);
1315 swap_pointers((void**)&locinfo
->lconv
->int_curr_symbol
,
1316 (void**)&loc
->locinfo
->lconv
->int_curr_symbol
);
1317 swap_pointers((void**)&locinfo
->lconv
->currency_symbol
,
1318 (void**)&loc
->locinfo
->lconv
->currency_symbol
);
1319 swap_pointers((void**)&locinfo
->lconv
->mon_decimal_point
,
1320 (void**)&loc
->locinfo
->lconv
->mon_decimal_point
);
1321 swap_pointers((void**)&locinfo
->lconv
->mon_thousands_sep
,
1322 (void**)&loc
->locinfo
->lconv
->mon_thousands_sep
);
1323 swap_pointers((void**)&locinfo
->lconv
->mon_grouping
,
1324 (void**)&loc
->locinfo
->lconv
->mon_grouping
);
1325 swap_pointers((void**)&locinfo
->lconv
->positive_sign
,
1326 (void**)&loc
->locinfo
->lconv
->positive_sign
);
1327 swap_pointers((void**)&locinfo
->lconv
->negative_sign
,
1328 (void**)&loc
->locinfo
->lconv
->negative_sign
);
1329 locinfo
->lconv
->int_frac_digits
= loc
->locinfo
->lconv
->int_frac_digits
;
1330 locinfo
->lconv
->frac_digits
= loc
->locinfo
->lconv
->frac_digits
;
1331 locinfo
->lconv
->p_cs_precedes
= loc
->locinfo
->lconv
->p_cs_precedes
;
1332 locinfo
->lconv
->p_sep_by_space
= loc
->locinfo
->lconv
->p_sep_by_space
;
1333 locinfo
->lconv
->n_cs_precedes
= loc
->locinfo
->lconv
->n_cs_precedes
;
1334 locinfo
->lconv
->n_sep_by_space
= loc
->locinfo
->lconv
->n_sep_by_space
;
1335 locinfo
->lconv
->p_sign_posn
= loc
->locinfo
->lconv
->p_sign_posn
;
1336 locinfo
->lconv
->n_sign_posn
= loc
->locinfo
->lconv
->n_sign_posn
;
1338 if(category
!= MSVCRT_LC_ALL
)
1341 case MSVCRT_LC_NUMERIC
:
1342 locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
] =
1343 loc
->locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
];
1344 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
,
1345 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
);
1346 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].refcount
,
1347 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].refcount
);
1349 swap_pointers((void**)&locinfo
->lconv
->decimal_point
,
1350 (void**)&loc
->locinfo
->lconv
->decimal_point
);
1351 swap_pointers((void**)&locinfo
->lconv
->thousands_sep
,
1352 (void**)&loc
->locinfo
->lconv
->thousands_sep
);
1353 swap_pointers((void**)&locinfo
->lconv
->grouping
,
1354 (void**)&loc
->locinfo
->lconv
->grouping
);
1356 if(category
!= MSVCRT_LC_ALL
)
1359 case MSVCRT_LC_TIME
:
1360 locinfo
->lc_handle
[MSVCRT_LC_TIME
] =
1361 loc
->locinfo
->lc_handle
[MSVCRT_LC_TIME
];
1362 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
,
1363 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
);
1364 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_TIME
].refcount
,
1365 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].refcount
);
1366 swap_pointers((void**)&locinfo
->lc_time_curr
,
1367 (void**)&loc
->locinfo
->lc_time_curr
);
1369 if(category
!= MSVCRT_LC_ALL
)
1373 MSVCRT__free_locale(loc
);
1376 if(locinfo
== MSVCRT_locale
->locinfo
) {
1379 MSVCRT___lc_codepage
= locinfo
->lc_codepage
;
1380 MSVCRT___lc_collate_cp
= locinfo
->lc_collate_cp
;
1381 MSVCRT___mb_cur_max
= locinfo
->mb_cur_max
;
1382 MSVCRT__pctype
= locinfo
->pctype
;
1383 for(i
=MSVCRT_LC_MIN
; i
<=MSVCRT_LC_MAX
; i
++)
1384 MSVCRT___lc_handle
[i
] = MSVCRT_locale
->locinfo
->lc_handle
[i
];
1387 if(category
== MSVCRT_LC_ALL
)
1388 return construct_lc_all(locinfo
);
1390 return locinfo
->lc_category
[category
].locale
;
1393 /* _configthreadlocale - not exported in native msvcrt */
1394 int CDECL
_configthreadlocale(int type
)
1396 thread_data_t
*data
= msvcrt_get_thread_data();
1397 MSVCRT__locale_t locale
;
1403 ret
= (data
->have_locale
? MSVCRT__ENABLE_PER_THREAD_LOCALE
: MSVCRT__DISABLE_PER_THREAD_LOCALE
);
1405 if(type
== MSVCRT__ENABLE_PER_THREAD_LOCALE
) {
1406 if(!data
->have_locale
) {
1407 /* Copy current global locale */
1408 locale
= MSVCRT__create_locale(MSVCRT_LC_ALL
, MSVCRT_setlocale(MSVCRT_LC_ALL
, NULL
));
1412 data
->locinfo
= locale
->locinfo
;
1413 data
->mbcinfo
= locale
->mbcinfo
;
1414 data
->have_locale
= TRUE
;
1415 MSVCRT_free(locale
);
1421 if(type
== MSVCRT__DISABLE_PER_THREAD_LOCALE
) {
1422 if(data
->have_locale
) {
1423 free_locinfo(data
->locinfo
);
1424 free_mbcinfo(data
->mbcinfo
);
1425 data
->locinfo
= MSVCRT_locale
->locinfo
;
1426 data
->mbcinfo
= MSVCRT_locale
->mbcinfo
;
1427 data
->have_locale
= FALSE
;
1439 BOOL
msvcrt_init_locale(void)
1444 MSVCRT_locale
= MSVCRT__create_locale(0, "C");
1449 MSVCRT___lc_codepage
= MSVCRT_locale
->locinfo
->lc_codepage
;
1450 MSVCRT___lc_collate_cp
= MSVCRT_locale
->locinfo
->lc_collate_cp
;
1451 MSVCRT___mb_cur_max
= MSVCRT_locale
->locinfo
->mb_cur_max
;
1452 MSVCRT__pctype
= MSVCRT_locale
->locinfo
->pctype
;
1453 for(i
=MSVCRT_LC_MIN
; i
<=MSVCRT_LC_MAX
; i
++)
1454 MSVCRT___lc_handle
[i
] = MSVCRT_locale
->locinfo
->lc_handle
[i
];
1455 _setmbcp(_MB_CP_ANSI
);