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 memcpy(name
, _country_synonyms
[i
+1], sizeof(_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(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(sizeof(char[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
, sizeof(char[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 const char* CDECL
_Getdays(void)
424 static const char MSVCRT_days
[] = ":Sun:Sunday:Mon:Monday:Tue:Tuesday:Wed:"
425 "Wednesday:Thu:Thursday:Fri:Friday:Sat:Saturday";
426 /* FIXME: Use locale */
427 TRACE("(void) semi-stub\n");
431 /*********************************************************************
432 * _Getmonths (MSVCRT.@)
434 const char* CDECL
_Getmonths(void)
436 static const char MSVCRT_months
[] = ":Jan:January:Feb:February:Mar:March:Apr:"
437 "April:May:May:Jun:June:Jul:July:Aug:August:Sep:September:Oct:"
438 "October:Nov:November:Dec:December";
439 /* FIXME: Use locale */
440 TRACE("(void) semi-stub\n");
441 return MSVCRT_months
;
444 /*********************************************************************
445 * _Gettnames (MSVCRT.@)
447 const char* CDECL
_Gettnames(void)
450 TRACE("(void) stub\n");
454 /*********************************************************************
455 * _Strftime (MSVCRT.@)
457 const char* CDECL
_Strftime(char *out
, unsigned int len
, const char *fmt
,
458 const void *tm
, void *foo
)
461 TRACE("(%p %d %s %p %p) stub\n", out
, len
, fmt
, tm
, foo
);
465 /*********************************************************************
466 * __crtLCMapStringA (MSVCRT.@)
468 int CDECL
__crtLCMapStringA(
469 LCID lcid
, DWORD mapflags
, const char* src
, int srclen
, char* dst
,
470 int dstlen
, unsigned int codepage
, int xflag
472 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
473 lcid
,mapflags
,src
,srclen
,dst
,dstlen
,codepage
,xflag
);
474 /* FIXME: A bit incorrect. But msvcrt itself just converts its
475 * arguments to wide strings and then calls LCMapStringW
477 return LCMapStringA(lcid
,mapflags
,src
,srclen
,dst
,dstlen
);
480 /*********************************************************************
481 * __crtLCMapStringW (MSVCRT.@)
483 int CDECL
__crtLCMapStringW(LCID lcid
, DWORD mapflags
, const MSVCRT_wchar_t
*src
,
484 int srclen
, MSVCRT_wchar_t
*dst
, int dstlen
, unsigned int codepage
, int xflag
)
486 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
487 lcid
, mapflags
, debugstr_w(src
), srclen
, dst
, dstlen
, codepage
, xflag
);
489 return LCMapStringW(lcid
, mapflags
, src
, srclen
, dst
, dstlen
);
492 /*********************************************************************
493 * __crtCompareStringA (MSVCRT.@)
495 int CDECL
__crtCompareStringA( LCID lcid
, DWORD flags
, const char *src1
, int len1
,
496 const char *src2
, int len2
)
498 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
499 lcid
, flags
, debugstr_a(src1
), len1
, debugstr_a(src2
), len2
);
500 /* FIXME: probably not entirely right */
501 return CompareStringA( lcid
, flags
, src1
, len1
, src2
, len2
);
504 /*********************************************************************
505 * __crtCompareStringW (MSVCRT.@)
507 int CDECL
__crtCompareStringW( LCID lcid
, DWORD flags
, const MSVCRT_wchar_t
*src1
, int len1
,
508 const MSVCRT_wchar_t
*src2
, int len2
)
510 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
511 lcid
, flags
, debugstr_w(src1
), len1
, debugstr_w(src2
), len2
);
512 /* FIXME: probably not entirely right */
513 return CompareStringW( lcid
, flags
, src1
, len1
, src2
, len2
);
516 /*********************************************************************
517 * __crtGetLocaleInfoW (MSVCRT.@)
519 int CDECL
__crtGetLocaleInfoW( LCID lcid
, LCTYPE type
, MSVCRT_wchar_t
*buffer
, int len
)
521 FIXME("(lcid %x, type %x, %p(%d), partial stub\n", lcid
, type
, buffer
, len
);
522 /* FIXME: probably not entirely right */
523 return GetLocaleInfoW( lcid
, type
, buffer
, len
);
526 /*********************************************************************
529 MSVCRT_wint_t CDECL
MSVCRT_btowc(int c
)
531 unsigned char letter
= c
;
534 if(!MultiByteToWideChar(get_locinfo()->lc_handle
[MSVCRT_LC_CTYPE
],
535 0, (LPCSTR
)&letter
, 1, &ret
, 1))
541 /*********************************************************************
542 * __crtGetStringTypeW(MSVCRT.@)
544 * This function was accepting different number of arguments in older
545 * versions of msvcrt.
547 BOOL CDECL
__crtGetStringTypeW(DWORD unk
, DWORD type
,
548 MSVCRT_wchar_t
*buffer
, int len
, WORD
*out
)
550 FIXME("(unk %x, type %x, wstr %p(%d), %p) partial stub\n",
551 unk
, type
, buffer
, len
, out
);
553 return GetStringTypeW(type
, buffer
, len
, out
);
556 /*********************************************************************
557 * localeconv (MSVCRT.@)
559 struct MSVCRT_lconv
* CDECL
MSVCRT_localeconv(void)
561 return get_locinfo()->lconv
;
564 /*********************************************************************
565 * __lconv_init (MSVCRT.@)
567 int CDECL
__lconv_init(void)
569 /* this is used to make chars unsigned */
574 /*********************************************************************
575 * ___lc_handle_func (MSVCRT.@)
577 LCID
* CDECL
___lc_handle_func(void)
579 return MSVCRT___lc_handle
;
582 /*********************************************************************
583 * ___lc_codepage_func (MSVCRT.@)
585 int CDECL
___lc_codepage_func(void)
587 return MSVCRT___lc_codepage
;
590 /*********************************************************************
591 * ___lc_collate_cp_func (MSVCRT.@)
593 int CDECL
___lc_collate_cp_func(void)
595 return get_locinfo()->lc_collate_cp
;
598 /* INTERNAL: frees MSVCRT_pthreadlocinfo struct */
599 void free_locinfo(MSVCRT_pthreadlocinfo locinfo
)
606 for(i
=MSVCRT_LC_MIN
+1; i
<=MSVCRT_LC_MAX
; i
++) {
607 MSVCRT_free(locinfo
->lc_category
[i
].locale
);
608 MSVCRT_free(locinfo
->lc_category
[i
].refcount
);
612 MSVCRT_free(locinfo
->lconv
->decimal_point
);
613 MSVCRT_free(locinfo
->lconv
->thousands_sep
);
614 MSVCRT_free(locinfo
->lconv
->grouping
);
615 MSVCRT_free(locinfo
->lconv
->int_curr_symbol
);
616 MSVCRT_free(locinfo
->lconv
->currency_symbol
);
617 MSVCRT_free(locinfo
->lconv
->mon_decimal_point
);
618 MSVCRT_free(locinfo
->lconv
->mon_thousands_sep
);
619 MSVCRT_free(locinfo
->lconv
->mon_grouping
);
620 MSVCRT_free(locinfo
->lconv
->positive_sign
);
621 MSVCRT_free(locinfo
->lconv
->negative_sign
);
623 MSVCRT_free(locinfo
->lconv_intl_refcount
);
624 MSVCRT_free(locinfo
->lconv_num_refcount
);
625 MSVCRT_free(locinfo
->lconv_mon_refcount
);
626 MSVCRT_free(locinfo
->lconv
);
628 MSVCRT_free(locinfo
->ctype1_refcount
);
629 MSVCRT_free(locinfo
->ctype1
);
631 MSVCRT_free(locinfo
->pclmap
);
632 MSVCRT_free(locinfo
->pcumap
);
634 MSVCRT_free(locinfo
);
637 /* INTERNAL: frees MSVCRT_pthreadmbcinfo struct */
638 void free_mbcinfo(MSVCRT_pthreadmbcinfo mbcinfo
)
643 MSVCRT_free(mbcinfo
);
646 /* _free_locale - not exported in native msvcrt */
647 void CDECL
MSVCRT__free_locale(MSVCRT__locale_t locale
)
652 free_locinfo(locale
->locinfo
);
653 free_mbcinfo(locale
->mbcinfo
);
657 /* _create_locale - not exported in native msvcrt */
658 MSVCRT__locale_t
MSVCRT__create_locale(int category
, const char *locale
)
660 static const char collate
[] = "COLLATE=";
661 static const char ctype
[] = "CTYPE=";
662 static const char monetary
[] = "MONETARY=";
663 static const char numeric
[] = "NUMERIC=";
664 static const char time
[] = "TIME=";
666 MSVCRT__locale_t loc
;
667 LCID lcid
[6] = { 0 };
671 TRACE("(%d %s)\n", category
, locale
);
673 if(category
<MSVCRT_LC_MIN
|| category
>MSVCRT_LC_MAX
|| !locale
)
676 if(locale
[0]=='C' && !locale
[1])
679 lcid
[0] = GetSystemDefaultLCID();
680 else if (locale
[0] == 'L' && locale
[1] == 'C' && locale
[2] == '_') {
684 locale
+= 3; /* LC_ */
685 if(!memcmp(locale
, collate
, sizeof(collate
)-1)) {
686 i
= MSVCRT_LC_COLLATE
;
687 locale
+= sizeof(collate
)-1;
688 } else if(!memcmp(locale
, ctype
, sizeof(ctype
)-1)) {
690 locale
+= sizeof(ctype
)-1;
691 } else if(!memcmp(locale
, monetary
, sizeof(monetary
)-1)) {
692 i
= MSVCRT_LC_MONETARY
;
693 locale
+= sizeof(monetary
)-1;
694 } else if(!memcmp(locale
, numeric
, sizeof(numeric
)-1)) {
695 i
= MSVCRT_LC_NUMERIC
;
696 locale
+= sizeof(numeric
)-1;
697 } else if(!memcmp(locale
, time
, sizeof(time
)-1)) {
699 locale
+= sizeof(time
)-1;
703 p
= strchr(locale
, ';');
704 if(locale
[0]=='C' && (locale
[1]==';' || locale
[1]=='\0'))
707 memcpy(buf
, locale
, p
-locale
);
708 buf
[p
-locale
] = '\0';
709 lcid
[i
] = MSVCRT_locale_to_LCID(buf
);
711 lcid
[i
] = MSVCRT_locale_to_LCID(locale
);
716 if(!p
|| *(p
+1)!='L' || *(p
+2)!='C' || *(p
+3)!='_')
722 lcid
[0] = MSVCRT_locale_to_LCID(locale
);
732 loc
= MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct
));
736 loc
->locinfo
= MSVCRT_malloc(sizeof(MSVCRT_threadlocinfo
));
742 loc
->mbcinfo
= MSVCRT_malloc(sizeof(MSVCRT_threadmbcinfo
));
744 MSVCRT_free(loc
->locinfo
);
749 memset(loc
->locinfo
, 0, sizeof(MSVCRT_threadlocinfo
));
751 loc
->locinfo
->lconv
= MSVCRT_malloc(sizeof(struct MSVCRT_lconv
));
752 if(!loc
->locinfo
->lconv
) {
753 MSVCRT__free_locale(loc
);
756 memset(loc
->locinfo
->lconv
, 0, sizeof(struct MSVCRT_lconv
));
758 loc
->locinfo
->pclmap
= MSVCRT_malloc(sizeof(char[256]));
759 loc
->locinfo
->pcumap
= MSVCRT_malloc(sizeof(char[256]));
760 if(!loc
->locinfo
->pclmap
|| !loc
->locinfo
->pcumap
) {
761 MSVCRT__free_locale(loc
);
765 loc
->locinfo
->refcount
= 1;
767 if(lcid
[MSVCRT_LC_COLLATE
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_COLLATE
)) {
768 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_COLLATE
], loc
, MSVCRT_LC_COLLATE
)) {
769 MSVCRT__free_locale(loc
);
773 loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
= MSVCRT__strdup("C");
775 if(lcid
[MSVCRT_LC_CTYPE
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_CTYPE
)) {
779 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_CTYPE
], loc
, MSVCRT_LC_CTYPE
)) {
780 MSVCRT__free_locale(loc
);
784 loc
->locinfo
->lc_codepage
= loc
->locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
;
785 loc
->locinfo
->lc_collate_cp
= loc
->locinfo
->lc_codepage
;
786 loc
->locinfo
->lc_clike
= 1;
787 if(!GetCPInfo(loc
->locinfo
->lc_codepage
, &cp
)) {
788 MSVCRT__free_locale(loc
);
791 loc
->locinfo
->mb_cur_max
= cp
.MaxCharSize
;
793 loc
->locinfo
->ctype1_refcount
= MSVCRT_malloc(sizeof(int));
794 loc
->locinfo
->ctype1
= MSVCRT_malloc(sizeof(short[257]));
795 if(!loc
->locinfo
->ctype1_refcount
|| !loc
->locinfo
->ctype1
) {
796 MSVCRT__free_locale(loc
);
800 *loc
->locinfo
->ctype1_refcount
= 1;
801 loc
->locinfo
->ctype1
[0] = 0;
802 loc
->locinfo
->pctype
= loc
->locinfo
->ctype1
+1;
804 buf
[1] = buf
[2] = '\0';
805 for(i
=1; i
<257; i
++) {
808 GetStringTypeA(lcid
[MSVCRT_LC_CTYPE
], CT_CTYPE1
, buf
,
809 1, loc
->locinfo
->ctype1
+i
);
812 for(i
=0; cp
.LeadByte
[i
+1]!=0; i
+=2)
813 for(j
=cp
.LeadByte
[i
]; j
<=cp
.LeadByte
[i
+1]; j
++)
814 loc
->locinfo
->ctype1
[j
+1] |= MSVCRT__LEADBYTE
;
816 loc
->locinfo
->lc_clike
= 1;
817 loc
->locinfo
->mb_cur_max
= 1;
818 loc
->locinfo
->pctype
= MSVCRT__ctype
+1;
819 loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
= MSVCRT__strdup("C");
822 for(i
=0; i
<256; i
++) {
823 if(loc
->locinfo
->pctype
[i
] & MSVCRT__LEADBYTE
)
830 if(lcid
[MSVCRT_LC_CTYPE
]) {
831 LCMapStringA(lcid
[MSVCRT_LC_CTYPE
], LCMAP_LOWERCASE
, buf
, 256,
832 (char*)loc
->locinfo
->pclmap
, 256);
833 LCMapStringA(lcid
[MSVCRT_LC_CTYPE
], LCMAP_UPPERCASE
, buf
, 256,
834 (char*)loc
->locinfo
->pcumap
, 256);
836 for(i
=0; i
<256; i
++) {
837 loc
->locinfo
->pclmap
[i
] = (i
>='A' && i
<='Z' ? i
-'A'+'a' : i
);
838 loc
->locinfo
->pcumap
[i
] = (i
>='a' && i
<='z' ? i
-'a'+'A' : i
);
842 _setmbcp_l(loc
->locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
, loc
->mbcinfo
);
844 if(lcid
[MSVCRT_LC_MONETARY
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_MONETARY
)) {
845 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_MONETARY
], loc
, MSVCRT_LC_MONETARY
)) {
846 MSVCRT__free_locale(loc
);
850 loc
->locinfo
->lconv_intl_refcount
= MSVCRT_malloc(sizeof(int));
851 loc
->locinfo
->lconv_mon_refcount
= MSVCRT_malloc(sizeof(int));
852 if(!loc
->locinfo
->lconv_intl_refcount
|| !loc
->locinfo
->lconv_mon_refcount
) {
853 MSVCRT__free_locale(loc
);
857 *loc
->locinfo
->lconv_intl_refcount
= 1;
858 *loc
->locinfo
->lconv_mon_refcount
= 1;
860 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SINTLSYMBOL
861 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
862 if(i
&& (loc
->locinfo
->lconv
->int_curr_symbol
= MSVCRT_malloc(sizeof(char[i
]))))
863 memcpy(loc
->locinfo
->lconv
->int_curr_symbol
, buf
, sizeof(char[i
]));
865 MSVCRT__free_locale(loc
);
869 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SCURRENCY
870 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
871 if(i
&& (loc
->locinfo
->lconv
->currency_symbol
= MSVCRT_malloc(sizeof(char[i
]))))
872 memcpy(loc
->locinfo
->lconv
->currency_symbol
, buf
, sizeof(char[i
]));
874 MSVCRT__free_locale(loc
);
878 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONDECIMALSEP
879 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
880 if(i
&& (loc
->locinfo
->lconv
->mon_decimal_point
= MSVCRT_malloc(sizeof(char[i
]))))
881 memcpy(loc
->locinfo
->lconv
->mon_decimal_point
, buf
, sizeof(char[i
]));
883 MSVCRT__free_locale(loc
);
887 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONTHOUSANDSEP
888 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
889 if(i
&& (loc
->locinfo
->lconv
->mon_thousands_sep
= MSVCRT_malloc(sizeof(char[i
]))))
890 memcpy(loc
->locinfo
->lconv
->mon_thousands_sep
, buf
, sizeof(char[i
]));
892 MSVCRT__free_locale(loc
);
896 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONGROUPING
897 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
899 i
= i
/2 + (buf
[i
-2]=='0'?0:1);
900 if(i
&& (loc
->locinfo
->lconv
->mon_grouping
= MSVCRT_malloc(sizeof(char[i
])))) {
901 for(i
=0; buf
[i
+1]==';'; i
+=2)
902 loc
->locinfo
->lconv
->mon_grouping
[i
/2] = buf
[i
]-'0';
903 loc
->locinfo
->lconv
->mon_grouping
[i
/2] = buf
[i
]-'0';
905 loc
->locinfo
->lconv
->mon_grouping
[i
/2+1] = 127;
907 MSVCRT__free_locale(loc
);
911 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SPOSITIVESIGN
912 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
913 if(i
&& (loc
->locinfo
->lconv
->positive_sign
= MSVCRT_malloc(sizeof(char[i
]))))
914 memcpy(loc
->locinfo
->lconv
->positive_sign
, buf
, sizeof(char[i
]));
916 MSVCRT__free_locale(loc
);
920 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SNEGATIVESIGN
921 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
922 if(i
&& (loc
->locinfo
->lconv
->negative_sign
= MSVCRT_malloc(sizeof(char[i
]))))
923 memcpy(loc
->locinfo
->lconv
->negative_sign
, buf
, sizeof(char[i
]));
925 MSVCRT__free_locale(loc
);
929 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IINTLCURRDIGITS
930 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
931 loc
->locinfo
->lconv
->int_frac_digits
= atoi(buf
);
933 MSVCRT__free_locale(loc
);
937 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_ICURRDIGITS
938 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
939 loc
->locinfo
->lconv
->frac_digits
= atoi(buf
);
941 MSVCRT__free_locale(loc
);
945 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSYMPRECEDES
946 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
947 loc
->locinfo
->lconv
->p_cs_precedes
= atoi(buf
);
949 MSVCRT__free_locale(loc
);
953 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSEPBYSPACE
954 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
955 loc
->locinfo
->lconv
->p_sep_by_space
= atoi(buf
);
957 MSVCRT__free_locale(loc
);
961 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSYMPRECEDES
962 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
963 loc
->locinfo
->lconv
->n_cs_precedes
= atoi(buf
);
965 MSVCRT__free_locale(loc
);
969 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSEPBYSPACE
970 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
971 loc
->locinfo
->lconv
->n_sep_by_space
= atoi(buf
);
973 MSVCRT__free_locale(loc
);
977 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSIGNPOSN
978 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
979 loc
->locinfo
->lconv
->p_sign_posn
= atoi(buf
);
981 MSVCRT__free_locale(loc
);
985 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSIGNPOSN
986 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
987 loc
->locinfo
->lconv
->n_sign_posn
= atoi(buf
);
989 MSVCRT__free_locale(loc
);
993 loc
->locinfo
->lconv
->int_curr_symbol
= MSVCRT_malloc(sizeof(char));
994 loc
->locinfo
->lconv
->currency_symbol
= MSVCRT_malloc(sizeof(char));
995 loc
->locinfo
->lconv
->mon_decimal_point
= MSVCRT_malloc(sizeof(char));
996 loc
->locinfo
->lconv
->mon_thousands_sep
= MSVCRT_malloc(sizeof(char));
997 loc
->locinfo
->lconv
->mon_grouping
= MSVCRT_malloc(sizeof(char));
998 loc
->locinfo
->lconv
->positive_sign
= MSVCRT_malloc(sizeof(char));
999 loc
->locinfo
->lconv
->negative_sign
= MSVCRT_malloc(sizeof(char));
1001 if(!loc
->locinfo
->lconv
->int_curr_symbol
|| !loc
->locinfo
->lconv
->currency_symbol
1002 || !loc
->locinfo
->lconv
->mon_decimal_point
|| !loc
->locinfo
->lconv
->mon_thousands_sep
1003 || !loc
->locinfo
->lconv
->mon_grouping
|| !loc
->locinfo
->lconv
->positive_sign
1004 || !loc
->locinfo
->lconv
->negative_sign
) {
1005 MSVCRT__free_locale(loc
);
1009 loc
->locinfo
->lconv
->int_curr_symbol
[0] = '\0';
1010 loc
->locinfo
->lconv
->currency_symbol
[0] = '\0';
1011 loc
->locinfo
->lconv
->mon_decimal_point
[0] = '\0';
1012 loc
->locinfo
->lconv
->mon_thousands_sep
[0] = '\0';
1013 loc
->locinfo
->lconv
->mon_grouping
[0] = '\0';
1014 loc
->locinfo
->lconv
->positive_sign
[0] = '\0';
1015 loc
->locinfo
->lconv
->negative_sign
[0] = '\0';
1016 loc
->locinfo
->lconv
->int_frac_digits
= 127;
1017 loc
->locinfo
->lconv
->frac_digits
= 127;
1018 loc
->locinfo
->lconv
->p_cs_precedes
= 127;
1019 loc
->locinfo
->lconv
->p_sep_by_space
= 127;
1020 loc
->locinfo
->lconv
->n_cs_precedes
= 127;
1021 loc
->locinfo
->lconv
->n_sep_by_space
= 127;
1022 loc
->locinfo
->lconv
->p_sign_posn
= 127;
1023 loc
->locinfo
->lconv
->n_sign_posn
= 127;
1025 loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
= MSVCRT__strdup("C");
1028 if(lcid
[MSVCRT_LC_NUMERIC
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_NUMERIC
)) {
1029 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_NUMERIC
], loc
, MSVCRT_LC_NUMERIC
)) {
1030 MSVCRT__free_locale(loc
);
1034 if(!loc
->locinfo
->lconv_intl_refcount
)
1035 loc
->locinfo
->lconv_intl_refcount
= MSVCRT_malloc(sizeof(int));
1036 loc
->locinfo
->lconv_num_refcount
= MSVCRT_malloc(sizeof(int));
1037 if(!loc
->locinfo
->lconv_intl_refcount
|| !loc
->locinfo
->lconv_num_refcount
) {
1038 MSVCRT__free_locale(loc
);
1042 *loc
->locinfo
->lconv_intl_refcount
= 1;
1043 *loc
->locinfo
->lconv_num_refcount
= 1;
1045 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SDECIMAL
1046 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1047 if(i
&& (loc
->locinfo
->lconv
->decimal_point
= MSVCRT_malloc(sizeof(char[i
]))))
1048 memcpy(loc
->locinfo
->lconv
->decimal_point
, buf
, sizeof(char[i
]));
1050 MSVCRT__free_locale(loc
);
1054 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_STHOUSAND
1055 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1056 if(i
&& (loc
->locinfo
->lconv
->thousands_sep
= MSVCRT_malloc(sizeof(char[i
]))))
1057 memcpy(loc
->locinfo
->lconv
->thousands_sep
, buf
, sizeof(char[i
]));
1059 MSVCRT__free_locale(loc
);
1063 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SGROUPING
1064 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1066 i
= i
/2 + (buf
[i
-2]=='0'?0:1);
1067 if(i
&& (loc
->locinfo
->lconv
->grouping
= MSVCRT_malloc(sizeof(char[i
])))) {
1068 for(i
=0; buf
[i
+1]==';'; i
+=2)
1069 loc
->locinfo
->lconv
->grouping
[i
/2] = buf
[i
]-'0';
1070 loc
->locinfo
->lconv
->grouping
[i
/2] = buf
[i
]-'0';
1072 loc
->locinfo
->lconv
->grouping
[i
/2+1] = 127;
1074 MSVCRT__free_locale(loc
);
1078 loc
->locinfo
->lconv
->decimal_point
= MSVCRT_malloc(sizeof(char[2]));
1079 loc
->locinfo
->lconv
->thousands_sep
= MSVCRT_malloc(sizeof(char));
1080 loc
->locinfo
->lconv
->grouping
= MSVCRT_malloc(sizeof(char));
1081 if(!loc
->locinfo
->lconv
->decimal_point
|| !loc
->locinfo
->lconv
->thousands_sep
1082 || !loc
->locinfo
->lconv
->grouping
) {
1083 MSVCRT__free_locale(loc
);
1087 loc
->locinfo
->lconv
->decimal_point
[0] = '.';
1088 loc
->locinfo
->lconv
->decimal_point
[1] = '\0';
1089 loc
->locinfo
->lconv
->thousands_sep
[0] = '\0';
1090 loc
->locinfo
->lconv
->grouping
[0] = '\0';
1092 loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
= MSVCRT__strdup("C");
1095 if(lcid
[MSVCRT_LC_TIME
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_TIME
)) {
1096 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_TIME
], loc
, MSVCRT_LC_TIME
)) {
1097 MSVCRT__free_locale(loc
);
1101 loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
= MSVCRT__strdup("C");
1106 /*********************************************************************
1107 * setlocale (MSVCRT.@)
1109 char* CDECL
MSVCRT_setlocale(int category
, const char* locale
)
1111 MSVCRT__locale_t loc
;
1112 MSVCRT_pthreadlocinfo locinfo
= get_locinfo();
1114 if(category
<MSVCRT_LC_MIN
|| category
>MSVCRT_LC_MAX
)
1118 if(category
== MSVCRT_LC_ALL
)
1119 return construct_lc_all(locinfo
);
1121 return locinfo
->lc_category
[category
].locale
;
1124 loc
= MSVCRT__create_locale(category
, locale
);
1126 WARN("%d %s failed\n", category
, locale
);
1134 case MSVCRT_LC_COLLATE
:
1135 locinfo
->lc_handle
[MSVCRT_LC_COLLATE
] =
1136 loc
->locinfo
->lc_handle
[MSVCRT_LC_COLLATE
];
1137 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
,
1138 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
);
1139 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_COLLATE
].refcount
,
1140 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].refcount
);
1142 if(category
!= MSVCRT_LC_ALL
)
1145 case MSVCRT_LC_CTYPE
:
1146 locinfo
->lc_handle
[MSVCRT_LC_CTYPE
] =
1147 loc
->locinfo
->lc_handle
[MSVCRT_LC_CTYPE
];
1148 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
,
1149 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
);
1150 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_CTYPE
].refcount
,
1151 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].refcount
);
1153 locinfo
->lc_codepage
= loc
->locinfo
->lc_codepage
;
1154 locinfo
->lc_collate_cp
= loc
->locinfo
->lc_collate_cp
;
1155 locinfo
->lc_clike
= loc
->locinfo
->lc_clike
;
1156 locinfo
->mb_cur_max
= loc
->locinfo
->mb_cur_max
;
1158 swap_pointers((void**)&locinfo
->ctype1_refcount
,
1159 (void**)&loc
->locinfo
->ctype1_refcount
);
1160 swap_pointers((void**)&locinfo
->ctype1
, (void**)&loc
->locinfo
->ctype1
);
1161 swap_pointers((void**)&locinfo
->pctype
, (void**)&loc
->locinfo
->pctype
);
1162 swap_pointers((void**)&locinfo
->pclmap
, (void**)&loc
->locinfo
->pclmap
);
1163 swap_pointers((void**)&locinfo
->pcumap
, (void**)&loc
->locinfo
->pcumap
);
1165 if(category
!= MSVCRT_LC_ALL
)
1168 case MSVCRT_LC_MONETARY
:
1169 locinfo
->lc_handle
[MSVCRT_LC_MONETARY
] =
1170 loc
->locinfo
->lc_handle
[MSVCRT_LC_MONETARY
];
1171 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
,
1172 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
);
1173 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_MONETARY
].refcount
,
1174 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].refcount
);
1176 swap_pointers((void**)&locinfo
->lconv
->int_curr_symbol
,
1177 (void**)&loc
->locinfo
->lconv
->int_curr_symbol
);
1178 swap_pointers((void**)&locinfo
->lconv
->currency_symbol
,
1179 (void**)&loc
->locinfo
->lconv
->currency_symbol
);
1180 swap_pointers((void**)&locinfo
->lconv
->mon_decimal_point
,
1181 (void**)&loc
->locinfo
->lconv
->mon_decimal_point
);
1182 swap_pointers((void**)&locinfo
->lconv
->mon_thousands_sep
,
1183 (void**)&loc
->locinfo
->lconv
->mon_thousands_sep
);
1184 swap_pointers((void**)&locinfo
->lconv
->mon_grouping
,
1185 (void**)&loc
->locinfo
->lconv
->mon_grouping
);
1186 swap_pointers((void**)&locinfo
->lconv
->positive_sign
,
1187 (void**)&loc
->locinfo
->lconv
->positive_sign
);
1188 swap_pointers((void**)&locinfo
->lconv
->negative_sign
,
1189 (void**)&loc
->locinfo
->lconv
->negative_sign
);
1190 locinfo
->lconv
->int_frac_digits
= loc
->locinfo
->lconv
->int_frac_digits
;
1191 locinfo
->lconv
->frac_digits
= loc
->locinfo
->lconv
->frac_digits
;
1192 locinfo
->lconv
->p_cs_precedes
= loc
->locinfo
->lconv
->p_cs_precedes
;
1193 locinfo
->lconv
->p_sep_by_space
= loc
->locinfo
->lconv
->p_sep_by_space
;
1194 locinfo
->lconv
->n_cs_precedes
= loc
->locinfo
->lconv
->n_cs_precedes
;
1195 locinfo
->lconv
->n_sep_by_space
= loc
->locinfo
->lconv
->n_sep_by_space
;
1196 locinfo
->lconv
->p_sign_posn
= loc
->locinfo
->lconv
->p_sign_posn
;
1197 locinfo
->lconv
->n_sign_posn
= loc
->locinfo
->lconv
->n_sign_posn
;
1199 if(category
!= MSVCRT_LC_ALL
)
1202 case MSVCRT_LC_NUMERIC
:
1203 locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
] =
1204 loc
->locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
];
1205 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
,
1206 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
);
1207 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].refcount
,
1208 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].refcount
);
1210 swap_pointers((void**)&locinfo
->lconv
->decimal_point
,
1211 (void**)&loc
->locinfo
->lconv
->decimal_point
);
1212 swap_pointers((void**)&locinfo
->lconv
->thousands_sep
,
1213 (void**)&loc
->locinfo
->lconv
->thousands_sep
);
1214 swap_pointers((void**)&locinfo
->lconv
->grouping
,
1215 (void**)&loc
->locinfo
->lconv
->grouping
);
1217 if(category
!= MSVCRT_LC_ALL
)
1220 case MSVCRT_LC_TIME
:
1221 locinfo
->lc_handle
[MSVCRT_LC_TIME
] =
1222 loc
->locinfo
->lc_handle
[MSVCRT_LC_TIME
];
1223 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
,
1224 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
);
1225 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_TIME
].refcount
,
1226 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].refcount
);
1228 if(category
!= MSVCRT_LC_ALL
)
1232 MSVCRT__free_locale(loc
);
1235 if(locinfo
== MSVCRT_locale
->locinfo
) {
1238 MSVCRT___lc_codepage
= locinfo
->lc_codepage
;
1239 MSVCRT___lc_collate_cp
= locinfo
->lc_collate_cp
;
1240 MSVCRT___mb_cur_max
= locinfo
->mb_cur_max
;
1241 MSVCRT__pctype
= locinfo
->pctype
;
1242 for(i
=MSVCRT_LC_MIN
; i
<=MSVCRT_LC_MAX
; i
++)
1243 MSVCRT___lc_handle
[i
] = MSVCRT_locale
->locinfo
->lc_handle
[i
];
1246 if(category
== MSVCRT_LC_ALL
)
1247 return construct_lc_all(locinfo
);
1249 return locinfo
->lc_category
[category
].locale
;
1252 /* _configthreadlocale - not exported in native msvcrt */
1253 int CDECL
_configthreadlocale(int type
)
1255 thread_data_t
*data
= msvcrt_get_thread_data();
1256 MSVCRT__locale_t locale
;
1262 ret
= (data
->have_locale
? MSVCRT__ENABLE_PER_THREAD_LOCALE
: MSVCRT__DISABLE_PER_THREAD_LOCALE
);
1264 if(type
== MSVCRT__ENABLE_PER_THREAD_LOCALE
) {
1265 if(!data
->have_locale
) {
1266 /* Copy current global locale */
1267 locale
= MSVCRT__create_locale(MSVCRT_LC_ALL
, MSVCRT_setlocale(MSVCRT_LC_ALL
, NULL
));
1271 data
->locinfo
= locale
->locinfo
;
1272 data
->mbcinfo
= locale
->mbcinfo
;
1273 data
->have_locale
= TRUE
;
1274 MSVCRT_free(locale
);
1280 if(type
== MSVCRT__DISABLE_PER_THREAD_LOCALE
) {
1281 if(data
->have_locale
) {
1282 free_locinfo(data
->locinfo
);
1283 free_mbcinfo(data
->mbcinfo
);
1284 data
->locinfo
= MSVCRT_locale
->locinfo
;
1285 data
->mbcinfo
= MSVCRT_locale
->mbcinfo
;
1286 data
->have_locale
= FALSE
;
1298 BOOL
msvcrt_init_locale(void)
1303 MSVCRT_locale
= MSVCRT__create_locale(0, "C");
1308 MSVCRT___lc_codepage
= MSVCRT_locale
->locinfo
->lc_codepage
;
1309 MSVCRT___lc_collate_cp
= MSVCRT_locale
->locinfo
->lc_collate_cp
;
1310 MSVCRT___mb_cur_max
= MSVCRT_locale
->locinfo
->mb_cur_max
;
1311 MSVCRT__pctype
= MSVCRT_locale
->locinfo
->pctype
;
1312 for(i
=MSVCRT_LC_MIN
; i
<=MSVCRT_LC_MAX
; i
++)
1313 MSVCRT___lc_handle
[i
] = MSVCRT_locale
->locinfo
->lc_handle
[i
];
1314 _setmbcp(_MB_CP_ANSI
);