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
;
52 #define MSVCRT_LEADBYTE 0x8000
53 #define MSVCRT_C1_DEFINED 0x200
55 /* Friendly country strings & language names abbreviations. */
56 static const char * const _country_synonyms
[] =
59 "american english", "enu",
60 "american-english", "enu",
61 "english-american", "enu",
69 "french-belgian", "frb",
72 "french-canadian", "frc",
74 "chinese-simplified", "chs",
75 "chinese-traditional", "cht",
76 "dutch-belgian", "nlb",
80 "french-swiss", "frs",
82 "german-swiss", "des",
83 "italian-swiss", "its",
84 "german-austrian", "dea",
86 "portuguese-brazil", "ptb",
87 "spanish-mexican", "esm",
88 "norwegian-bokmal", "nor",
89 "norwegian-nynorsk", "non",
90 "spanish-modern", "esn"
93 /* INTERNAL: Map a synonym to an ISO code */
94 static void remap_synonym(char *name
)
97 for (i
= 0; i
< sizeof(_country_synonyms
)/sizeof(char*); i
+= 2 )
99 if (!strcasecmp(_country_synonyms
[i
],name
))
101 TRACE(":Mapping synonym %s to %s\n",name
,_country_synonyms
[i
+1]);
102 strcpy(name
, _country_synonyms
[i
+1]);
108 /* Note: Flags are weighted in order of matching importance */
109 #define FOUND_LANGUAGE 0x4
110 #define FOUND_COUNTRY 0x2
111 #define FOUND_CODEPAGE 0x1
114 char search_language
[MAX_ELEM_LEN
];
115 char search_country
[MAX_ELEM_LEN
];
116 char search_codepage
[MAX_ELEM_LEN
];
117 char found_codepage
[MAX_ELEM_LEN
];
118 unsigned int match_flags
;
119 LANGID found_lang_id
;
122 #define CONTINUE_LOOKING TRUE
123 #define STOP_LOOKING FALSE
125 /* INTERNAL: Get and compare locale info with a given string */
126 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
);
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 (!flags
&& (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 (!flags
&& (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
, unsigned short *codepage
)
216 thread_data_t
*data
= msvcrt_get_thread_data();
218 locale_search_t search
;
219 const char *cp
, *region
;
221 if (!strcmp(locale
, data
->cached_locale
)) {
223 *codepage
= data
->cached_cp
;
224 return data
->cached_lcid
;
227 memset(&search
, 0, sizeof(locale_search_t
));
229 cp
= strchr(locale
, '.');
230 region
= strchr(locale
, '_');
232 lstrcpynA(search
.search_language
, locale
, MAX_ELEM_LEN
);
234 lstrcpynA(search
.search_country
, region
+1, MAX_ELEM_LEN
);
235 if(region
-locale
< MAX_ELEM_LEN
)
236 search
.search_language
[region
-locale
] = '\0';
238 search
.search_country
[0] = '\0';
241 lstrcpynA(search
.search_codepage
, cp
+1, MAX_ELEM_LEN
);
242 if(region
&& cp
-region
-1<MAX_ELEM_LEN
)
243 search
.search_country
[cp
-region
-1] = '\0';
244 if(cp
-locale
< MAX_ELEM_LEN
)
245 search
.search_language
[cp
-locale
] = '\0';
247 search
.search_codepage
[0] = '\0';
249 if(!search
.search_country
[0] && !search
.search_codepage
[0])
250 remap_synonym(search
.search_language
);
252 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), (LPSTR
)RT_STRING
,
253 (LPCSTR
)LOCALE_ILANGUAGE
,find_best_locale_proc
,
256 if (!search
.match_flags
)
259 /* If we were given something that didn't match, fail */
260 if (search
.search_country
[0] && !(search
.match_flags
& FOUND_COUNTRY
))
263 lcid
= MAKELCID(search
.found_lang_id
, SORT_DEFAULT
);
265 /* Populate partial locale, translating LCID to locale string elements */
266 if (!(search
.match_flags
& FOUND_CODEPAGE
)) {
267 /* Even if a codepage is not enumerated for a locale
268 * it can be set if valid */
269 if (search
.search_codepage
[0]) {
270 if (IsValidCodePage(atoi(search
.search_codepage
)))
271 memcpy(search
.found_codepage
,search
.search_codepage
,MAX_ELEM_LEN
);
273 /* Special codepage values: OEM & ANSI */
274 if (!strcasecmp(search
.search_codepage
,"OCP")) {
275 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTCODEPAGE
,
276 search
.found_codepage
, MAX_ELEM_LEN
);
277 } else if (!strcasecmp(search
.search_codepage
,"ACP")) {
278 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
,
279 search
.found_codepage
, MAX_ELEM_LEN
);
283 if (!atoi(search
.found_codepage
))
287 /* Prefer ANSI codepages if present */
288 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
,
289 search
.found_codepage
, MAX_ELEM_LEN
);
290 if (!search
.found_codepage
[0] || !atoi(search
.found_codepage
))
291 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTCODEPAGE
,
292 search
.found_codepage
, MAX_ELEM_LEN
);
296 *codepage
= atoi(search
.found_codepage
);
298 if (strlen(locale
) < sizeof(data
->cached_locale
)) {
299 strcpy(data
->cached_locale
, locale
);
300 data
->cached_lcid
= lcid
;
301 data
->cached_cp
= codepage
? *codepage
: atoi(search
.found_codepage
);
307 /* INTERNAL: Set lc_handle, lc_id and lc_category in threadlocinfo struct */
308 static BOOL
update_threadlocinfo_category(LCID lcid
, unsigned short cp
,
309 MSVCRT_pthreadlocinfo locinfo
, int category
)
314 if(GetLocaleInfoA(lcid
, LOCALE_ILANGUAGE
|LOCALE_NOUSEROVERRIDE
, buf
, 256)) {
317 locinfo
->lc_id
[category
].wLanguage
= 0;
319 locinfo
->lc_id
[category
].wLanguage
*= 16;
322 locinfo
->lc_id
[category
].wLanguage
+= *p
-'0';
324 locinfo
->lc_id
[category
].wLanguage
+= *p
-'a'+10;
329 locinfo
->lc_id
[category
].wCountry
=
330 locinfo
->lc_id
[category
].wLanguage
;
333 locinfo
->lc_id
[category
].wCodePage
= cp
;
335 locinfo
->lc_handle
[category
] = lcid
;
338 len
+= GetLocaleInfoA(lcid
, LOCALE_SENGLANGUAGE
339 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
341 len
+= GetLocaleInfoA(lcid
, LOCALE_SENGCOUNTRY
342 |LOCALE_NOUSEROVERRIDE
, &buf
[len
], 256-len
);
344 sprintf(buf
+len
, "%d", cp
);
345 len
+= strlen(buf
+len
)+1;
347 locinfo
->lc_category
[category
].locale
= MSVCRT_malloc(len
);
348 locinfo
->lc_category
[category
].refcount
= MSVCRT_malloc(sizeof(int));
349 if(!locinfo
->lc_category
[category
].locale
350 || !locinfo
->lc_category
[category
].refcount
) {
351 MSVCRT_free(locinfo
->lc_category
[category
].locale
);
352 MSVCRT_free(locinfo
->lc_category
[category
].refcount
);
353 locinfo
->lc_category
[category
].locale
= NULL
;
354 locinfo
->lc_category
[category
].refcount
= NULL
;
357 memcpy(locinfo
->lc_category
[category
].locale
, buf
, len
);
358 *locinfo
->lc_category
[category
].refcount
= 1;
363 /* INTERNAL: swap pointers values */
364 static inline void swap_pointers(void **p1
, void **p2
) {
372 /* INTERNAL: returns pthreadlocinfo struct */
373 MSVCRT_pthreadlocinfo
get_locinfo(void) {
374 thread_data_t
*data
= msvcrt_get_thread_data();
376 if(!data
|| !data
->have_locale
)
377 return MSVCRT_locale
->locinfo
;
379 return data
->locinfo
;
382 /* INTERNAL: returns pthreadlocinfo struct */
383 MSVCRT_pthreadmbcinfo
get_mbcinfo(void) {
384 thread_data_t
*data
= msvcrt_get_thread_data();
386 if(!data
|| !data
->have_locale
)
387 return MSVCRT_locale
->mbcinfo
;
389 return data
->mbcinfo
;
392 /* INTERNAL: constructs string returned by setlocale */
393 static inline char* construct_lc_all(MSVCRT_pthreadlocinfo locinfo
) {
394 static char current_lc_all
[MAX_LOCALE_LENGTH
];
398 for(i
=MSVCRT_LC_MIN
+1; i
<MSVCRT_LC_MAX
; i
++) {
399 if(strcmp(locinfo
->lc_category
[i
].locale
,
400 locinfo
->lc_category
[i
+1].locale
))
405 return locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
;
407 sprintf(current_lc_all
,
408 "LC_COLLATE=%s;LC_CTYPE=%s;LC_MONETARY=%s;LC_NUMERIC=%s;LC_TIME=%s",
409 locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
,
410 locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
,
411 locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
,
412 locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
,
413 locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
);
415 return current_lc_all
;
419 /*********************************************************************
420 * _Getdays (MSVCRT.@)
422 char* CDECL
_Getdays(void)
424 MSVCRT___lc_time_data
*cur
= get_locinfo()->lc_time_curr
;
430 size
= cur
->str
.names
.short_mon
[0]-cur
->str
.names
.short_wday
[0];
431 out
= MSVCRT_malloc(size
+1);
438 len
= strlen(cur
->str
.names
.short_wday
[i
]);
439 memcpy(&out
[size
], cur
->str
.names
.short_wday
[i
], len
);
443 len
= strlen(cur
->str
.names
.wday
[i
]);
444 memcpy(&out
[size
], cur
->str
.names
.wday
[i
], len
);
452 /*********************************************************************
453 * _W_Getdays (MSVCRT.@)
455 MSVCRT_wchar_t
* CDECL
_W_Getdays(void)
457 MSVCRT___lc_time_data
*cur
= get_locinfo()->lc_time_curr
;
463 size
= cur
->wstr
.names
.short_mon
[0]-cur
->wstr
.names
.short_wday
[0];
464 out
= MSVCRT_malloc((size
+1)*sizeof(*out
));
471 len
= strlenW(cur
->wstr
.names
.short_wday
[i
]);
472 memcpy(&out
[size
], cur
->wstr
.names
.short_wday
[i
], len
*sizeof(*out
));
476 len
= strlenW(cur
->wstr
.names
.wday
[i
]);
477 memcpy(&out
[size
], cur
->wstr
.names
.wday
[i
], len
*sizeof(*out
));
485 /*********************************************************************
486 * _Getmonths (MSVCRT.@)
488 char* CDECL
_Getmonths(void)
490 MSVCRT___lc_time_data
*cur
= get_locinfo()->lc_time_curr
;
496 size
= cur
->str
.names
.am
-cur
->str
.names
.short_mon
[0];
497 out
= MSVCRT_malloc(size
+1);
502 for(i
=0; i
<12; i
++) {
504 len
= strlen(cur
->str
.names
.short_mon
[i
]);
505 memcpy(&out
[size
], cur
->str
.names
.short_mon
[i
], len
);
509 len
= strlen(cur
->str
.names
.mon
[i
]);
510 memcpy(&out
[size
], cur
->str
.names
.mon
[i
], len
);
518 /*********************************************************************
519 * _W_Getmonths (MSVCRT.@)
521 MSVCRT_wchar_t
* CDECL
_W_Getmonths(void)
523 MSVCRT___lc_time_data
*cur
= get_locinfo()->lc_time_curr
;
529 size
= cur
->wstr
.names
.am
-cur
->wstr
.names
.short_mon
[0];
530 out
= MSVCRT_malloc((size
+1)*sizeof(*out
));
535 for(i
=0; i
<12; i
++) {
537 len
= strlenW(cur
->wstr
.names
.short_mon
[i
]);
538 memcpy(&out
[size
], cur
->wstr
.names
.short_mon
[i
], len
*sizeof(*out
));
542 len
= strlenW(cur
->wstr
.names
.mon
[i
]);
543 memcpy(&out
[size
], cur
->wstr
.names
.mon
[i
], len
*sizeof(*out
));
551 /*********************************************************************
552 * _Gettnames (MSVCRT.@)
554 void* CDECL
_Gettnames(void)
556 MSVCRT___lc_time_data
*ret
, *cur
= get_locinfo()->lc_time_curr
;
557 unsigned int i
, size
= sizeof(MSVCRT___lc_time_data
);
561 for(i
=0; i
<sizeof(cur
->str
.str
)/sizeof(cur
->str
.str
[0]); i
++)
562 size
+= strlen(cur
->str
.str
[i
])+1;
564 ret
= MSVCRT_malloc(size
);
567 memcpy(ret
, cur
, size
);
570 for(i
=0; i
<sizeof(cur
->str
.str
)/sizeof(cur
->str
.str
[0]); i
++) {
571 ret
->str
.str
[i
] = &ret
->data
[size
];
572 size
+= strlen(&ret
->data
[size
])+1;
578 /*********************************************************************
579 * _W_Gettnames (MSVCR110.@)
581 void* CDECL
_W_Gettnames(void)
586 /*********************************************************************
587 * __crtLCMapStringA (MSVCRT.@)
589 int CDECL
__crtLCMapStringA(
590 LCID lcid
, DWORD mapflags
, const char* src
, int srclen
, char* dst
,
591 int dstlen
, unsigned int codepage
, int xflag
593 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
594 lcid
,mapflags
,src
,srclen
,dst
,dstlen
,codepage
,xflag
);
595 /* FIXME: A bit incorrect. But msvcrt itself just converts its
596 * arguments to wide strings and then calls LCMapStringW
598 return LCMapStringA(lcid
,mapflags
,src
,srclen
,dst
,dstlen
);
601 /*********************************************************************
602 * __crtLCMapStringW (MSVCRT.@)
604 int CDECL
__crtLCMapStringW(LCID lcid
, DWORD mapflags
, const MSVCRT_wchar_t
*src
,
605 int srclen
, MSVCRT_wchar_t
*dst
, int dstlen
, unsigned int codepage
, int xflag
)
607 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
608 lcid
, mapflags
, debugstr_w(src
), srclen
, dst
, dstlen
, codepage
, xflag
);
610 return LCMapStringW(lcid
, mapflags
, src
, srclen
, dst
, dstlen
);
613 /*********************************************************************
614 * __crtCompareStringA (MSVCRT.@)
616 int CDECL
__crtCompareStringA( LCID lcid
, DWORD flags
, const char *src1
, int len1
,
617 const char *src2
, int len2
)
619 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
620 lcid
, flags
, debugstr_a(src1
), len1
, debugstr_a(src2
), len2
);
621 /* FIXME: probably not entirely right */
622 return CompareStringA( lcid
, flags
, src1
, len1
, src2
, len2
);
625 /*********************************************************************
626 * __crtCompareStringW (MSVCRT.@)
628 int CDECL
__crtCompareStringW( LCID lcid
, DWORD flags
, const MSVCRT_wchar_t
*src1
, int len1
,
629 const MSVCRT_wchar_t
*src2
, int len2
)
631 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
632 lcid
, flags
, debugstr_w(src1
), len1
, debugstr_w(src2
), len2
);
633 /* FIXME: probably not entirely right */
634 return CompareStringW( lcid
, flags
, src1
, len1
, src2
, len2
);
637 /*********************************************************************
638 * __crtGetLocaleInfoW (MSVCRT.@)
640 int CDECL
__crtGetLocaleInfoW( LCID lcid
, LCTYPE type
, MSVCRT_wchar_t
*buffer
, int len
)
642 FIXME("(lcid %x, type %x, %p(%d), partial stub\n", lcid
, type
, buffer
, len
);
643 /* FIXME: probably not entirely right */
644 return GetLocaleInfoW( lcid
, type
, buffer
, len
);
647 /*********************************************************************
648 * __crtGetLocaleInfoEx (MSVC110.@)
650 int CDECL
__crtGetLocaleInfoEx( const WCHAR
*locale
, LCTYPE type
, MSVCRT_wchar_t
*buffer
, int len
)
652 TRACE("(%s, %x, %p, %d)\n", debugstr_w(locale
), type
, buffer
, len
);
653 return GetLocaleInfoEx(locale
, type
, buffer
, len
);
656 /*********************************************************************
659 MSVCRT_wint_t CDECL
MSVCRT_btowc(int c
)
661 unsigned char letter
= c
;
664 if(!MultiByteToWideChar(get_locinfo()->lc_handle
[MSVCRT_LC_CTYPE
],
665 0, (LPCSTR
)&letter
, 1, &ret
, 1))
671 /*********************************************************************
672 * __crtGetStringTypeW(MSVCRT.@)
674 * This function was accepting different number of arguments in older
675 * versions of msvcrt.
677 BOOL CDECL
__crtGetStringTypeW(DWORD unk
, DWORD type
,
678 MSVCRT_wchar_t
*buffer
, int len
, WORD
*out
)
680 FIXME("(unk %x, type %x, wstr %p(%d), %p) partial stub\n",
681 unk
, type
, buffer
, len
, out
);
683 return GetStringTypeW(type
, buffer
, len
, out
);
686 /*********************************************************************
687 * localeconv (MSVCRT.@)
689 struct MSVCRT_lconv
* CDECL
MSVCRT_localeconv(void)
691 return get_locinfo()->lconv
;
694 /*********************************************************************
695 * __lconv_init (MSVCRT.@)
697 int CDECL
__lconv_init(void)
699 /* this is used to make chars unsigned */
704 /*********************************************************************
705 * ___lc_handle_func (MSVCRT.@)
707 LCID
* CDECL
___lc_handle_func(void)
709 return get_locinfo()->lc_handle
;
712 /*********************************************************************
713 * ___lc_locale_name_func (MSVCR110.@)
715 #if _MSVCR_VER >= 110
716 MSVCRT_wchar_t
** CDECL
___lc_locale_name_func(void)
718 return get_locinfo()->lc_name
;
722 /*********************************************************************
723 * ___lc_codepage_func (MSVCRT.@)
725 unsigned int CDECL
___lc_codepage_func(void)
727 return get_locinfo()->lc_codepage
;
730 /*********************************************************************
731 * ___lc_collate_cp_func (MSVCRT.@)
733 int CDECL
___lc_collate_cp_func(void)
735 return get_locinfo()->lc_collate_cp
;
738 /* INTERNAL: frees MSVCRT_pthreadlocinfo struct */
739 void free_locinfo(MSVCRT_pthreadlocinfo locinfo
)
746 if(InterlockedDecrement(&locinfo
->refcount
))
749 for(i
=MSVCRT_LC_MIN
+1; i
<=MSVCRT_LC_MAX
; i
++) {
750 MSVCRT_free(locinfo
->lc_category
[i
].locale
);
751 MSVCRT_free(locinfo
->lc_category
[i
].refcount
);
752 #if _MSVCR_VER >= 110
753 MSVCRT_free(locinfo
->lc_name
[i
]);
758 MSVCRT_free(locinfo
->lconv
->decimal_point
);
759 MSVCRT_free(locinfo
->lconv
->thousands_sep
);
760 MSVCRT_free(locinfo
->lconv
->grouping
);
761 MSVCRT_free(locinfo
->lconv
->int_curr_symbol
);
762 MSVCRT_free(locinfo
->lconv
->currency_symbol
);
763 MSVCRT_free(locinfo
->lconv
->mon_decimal_point
);
764 MSVCRT_free(locinfo
->lconv
->mon_thousands_sep
);
765 MSVCRT_free(locinfo
->lconv
->mon_grouping
);
766 MSVCRT_free(locinfo
->lconv
->positive_sign
);
767 MSVCRT_free(locinfo
->lconv
->negative_sign
);
768 #if _MSVCR_VER >= 100
769 MSVCRT_free(locinfo
->lconv
->_W_decimal_point
);
770 MSVCRT_free(locinfo
->lconv
->_W_thousands_sep
);
771 MSVCRT_free(locinfo
->lconv
->_W_int_curr_symbol
);
772 MSVCRT_free(locinfo
->lconv
->_W_currency_symbol
);
773 MSVCRT_free(locinfo
->lconv
->_W_mon_decimal_point
);
774 MSVCRT_free(locinfo
->lconv
->_W_mon_thousands_sep
);
775 MSVCRT_free(locinfo
->lconv
->_W_positive_sign
);
776 MSVCRT_free(locinfo
->lconv
->_W_negative_sign
);
779 MSVCRT_free(locinfo
->lconv_intl_refcount
);
780 MSVCRT_free(locinfo
->lconv_num_refcount
);
781 MSVCRT_free(locinfo
->lconv_mon_refcount
);
782 MSVCRT_free(locinfo
->lconv
);
784 MSVCRT_free(locinfo
->ctype1_refcount
);
785 MSVCRT_free(locinfo
->ctype1
);
787 MSVCRT_free(locinfo
->pclmap
);
788 MSVCRT_free(locinfo
->pcumap
);
790 MSVCRT_free(locinfo
->lc_time_curr
);
792 MSVCRT_free(locinfo
);
795 /* INTERNAL: frees MSVCRT_pthreadmbcinfo struct */
796 void free_mbcinfo(MSVCRT_pthreadmbcinfo mbcinfo
)
801 if(InterlockedDecrement(&mbcinfo
->refcount
))
804 MSVCRT_free(mbcinfo
);
807 /*********************************************************************
808 * _get_current_locale (MSVCRT.@)
810 MSVCRT__locale_t CDECL
MSVCRT__get_current_locale(void)
812 MSVCRT__locale_t loc
= MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct
));
816 loc
->locinfo
= get_locinfo();
817 loc
->mbcinfo
= get_mbcinfo();
818 InterlockedIncrement(&loc
->locinfo
->refcount
);
819 InterlockedIncrement(&loc
->mbcinfo
->refcount
);
823 /*********************************************************************
824 * _free_locale (MSVCRT.@)
826 void CDECL
MSVCRT__free_locale(MSVCRT__locale_t locale
)
831 free_locinfo(locale
->locinfo
);
832 free_mbcinfo(locale
->mbcinfo
);
836 #if _MSVCR_VER >= 110
837 static inline BOOL
set_lc_locale_name(MSVCRT_pthreadlocinfo locinfo
, int cat
)
839 LCID lcid
= locinfo
->lc_handle
[cat
];
843 len
= GetLocaleInfoW(lcid
, LOCALE_SISO639LANGNAME
844 |LOCALE_NOUSEROVERRIDE
, buf
, 100);
845 if(!len
) return FALSE
;
847 if(LocaleNameToLCID(buf
, 0) != lcid
)
848 len
= LCIDToLocaleName(lcid
, buf
, 100, 0);
850 if(!len
|| !(locinfo
->lc_name
[cat
] = MSVCRT_malloc(len
*sizeof(MSVCRT_wchar_t
))))
853 memcpy(locinfo
->lc_name
[cat
], buf
, len
*sizeof(MSVCRT_wchar_t
));
857 static inline BOOL
set_lc_locale_name(MSVCRT_pthreadlocinfo locinfo
, int cat
)
863 static inline BOOL
category_needs_update(int cat
, int user_cat
,
864 MSVCRT_pthreadlocinfo locinfo
, LCID lcid
, unsigned short cp
)
866 if(!locinfo
) return TRUE
;
867 if(user_cat
!=cat
&& user_cat
!=MSVCRT_LC_ALL
) return FALSE
;
868 return lcid
!=locinfo
->lc_handle
[cat
] || cp
!=locinfo
->lc_id
[cat
].wCodePage
;
871 static MSVCRT_pthreadlocinfo
create_locinfo(int category
,
872 const char *locale
, MSVCRT_pthreadlocinfo old_locinfo
)
874 static const DWORD time_data
[] = {
875 LOCALE_SABBREVDAYNAME7
, LOCALE_SABBREVDAYNAME1
, LOCALE_SABBREVDAYNAME2
,
876 LOCALE_SABBREVDAYNAME3
, LOCALE_SABBREVDAYNAME4
, LOCALE_SABBREVDAYNAME5
,
877 LOCALE_SABBREVDAYNAME6
,
878 LOCALE_SDAYNAME7
, LOCALE_SDAYNAME1
, LOCALE_SDAYNAME2
, LOCALE_SDAYNAME3
,
879 LOCALE_SDAYNAME4
, LOCALE_SDAYNAME5
, LOCALE_SDAYNAME6
,
880 LOCALE_SABBREVMONTHNAME1
, LOCALE_SABBREVMONTHNAME2
, LOCALE_SABBREVMONTHNAME3
,
881 LOCALE_SABBREVMONTHNAME4
, LOCALE_SABBREVMONTHNAME5
, LOCALE_SABBREVMONTHNAME6
,
882 LOCALE_SABBREVMONTHNAME7
, LOCALE_SABBREVMONTHNAME8
, LOCALE_SABBREVMONTHNAME9
,
883 LOCALE_SABBREVMONTHNAME10
, LOCALE_SABBREVMONTHNAME11
, LOCALE_SABBREVMONTHNAME12
,
884 LOCALE_SMONTHNAME1
, LOCALE_SMONTHNAME2
, LOCALE_SMONTHNAME3
, LOCALE_SMONTHNAME4
,
885 LOCALE_SMONTHNAME5
, LOCALE_SMONTHNAME6
, LOCALE_SMONTHNAME7
, LOCALE_SMONTHNAME8
,
886 LOCALE_SMONTHNAME9
, LOCALE_SMONTHNAME10
, LOCALE_SMONTHNAME11
, LOCALE_SMONTHNAME12
,
887 LOCALE_S1159
, LOCALE_S2359
,
888 LOCALE_SSHORTDATE
, LOCALE_SLONGDATE
,
891 static const char collate
[] = "COLLATE=";
892 static const char ctype
[] = "CTYPE=";
893 static const char monetary
[] = "MONETARY=";
894 static const char numeric
[] = "NUMERIC=";
895 static const char time
[] = "TIME=";
896 static const char cloc_short_date
[] = "MM/dd/yy";
897 static const MSVCRT_wchar_t cloc_short_dateW
[] = {'M','M','/','d','d','/','y','y',0};
898 static const char cloc_long_date
[] = "dddd, MMMM dd, yyyy";
899 static const MSVCRT_wchar_t cloc_long_dateW
[] = {'d','d','d','d',',',' ','M','M','M','M',' ','d','d',',',' ','y','y','y','y',0};
900 static const char cloc_time
[] = "HH:mm:ss";
901 static const MSVCRT_wchar_t cloc_timeW
[] = {'H','H',':','m','m',':','s','s',0};
903 MSVCRT_pthreadlocinfo locinfo
;
904 LCID lcid
[6] = { 0 }, lcid_tmp
;
905 unsigned short cp
[6] = { 0 };
907 #if _MSVCR_VER >= 100
908 MSVCRT_wchar_t wbuf
[256];
912 TRACE("(%d %s)\n", category
, locale
);
914 if(category
<MSVCRT_LC_MIN
|| category
>MSVCRT_LC_MAX
|| !locale
)
917 if(locale
[0]=='C' && !locale
[1]) {
920 } else if(!locale
[0]) {
921 lcid
[0] = GetSystemDefaultLCID();
922 GetLocaleInfoA(lcid
[0], LOCALE_IDEFAULTANSICODEPAGE
923 |LOCALE_NOUSEROVERRIDE
, buf
, sizeof(buf
));
930 } else if (locale
[0] == 'L' && locale
[1] == 'C' && locale
[2] == '_') {
934 locale
+= 3; /* LC_ */
935 if(!memcmp(locale
, collate
, sizeof(collate
)-1)) {
936 i
= MSVCRT_LC_COLLATE
;
937 locale
+= sizeof(collate
)-1;
938 } else if(!memcmp(locale
, ctype
, sizeof(ctype
)-1)) {
940 locale
+= sizeof(ctype
)-1;
941 } else if(!memcmp(locale
, monetary
, sizeof(monetary
)-1)) {
942 i
= MSVCRT_LC_MONETARY
;
943 locale
+= sizeof(monetary
)-1;
944 } else if(!memcmp(locale
, numeric
, sizeof(numeric
)-1)) {
945 i
= MSVCRT_LC_NUMERIC
;
946 locale
+= sizeof(numeric
)-1;
947 } else if(!memcmp(locale
, time
, sizeof(time
)-1)) {
949 locale
+= sizeof(time
)-1;
953 p
= strchr(locale
, ';');
954 if(locale
[0]=='C' && (locale
[1]==';' || locale
[1]=='\0')) {
958 memcpy(buf
, locale
, p
-locale
);
959 buf
[p
-locale
] = '\0';
960 lcid
[i
] = MSVCRT_locale_to_LCID(buf
, &cp
[i
]);
962 lcid
[i
] = MSVCRT_locale_to_LCID(locale
, &cp
[i
]);
967 if(!p
|| *(p
+1)!='L' || *(p
+2)!='C' || *(p
+3)!='_')
973 lcid
[0] = MSVCRT_locale_to_LCID(locale
, &cp
[0]);
983 locinfo
= MSVCRT_malloc(sizeof(MSVCRT_threadlocinfo
));
987 memset(locinfo
, 0, sizeof(MSVCRT_threadlocinfo
));
988 locinfo
->refcount
= 1;
990 locinfo
->lconv
= MSVCRT_malloc(sizeof(struct MSVCRT_lconv
));
991 if(!locinfo
->lconv
) {
992 free_locinfo(locinfo
);
995 memset(locinfo
->lconv
, 0, sizeof(struct MSVCRT_lconv
));
997 locinfo
->pclmap
= MSVCRT_malloc(sizeof(char[256]));
998 locinfo
->pcumap
= MSVCRT_malloc(sizeof(char[256]));
999 if(!locinfo
->pclmap
|| !locinfo
->pcumap
) {
1000 free_locinfo(locinfo
);
1004 if(!category_needs_update(MSVCRT_LC_COLLATE
, category
, old_locinfo
,
1005 lcid
[MSVCRT_LC_COLLATE
], cp
[MSVCRT_LC_COLLATE
])) {
1006 locinfo
->lc_handle
[MSVCRT_LC_COLLATE
] = old_locinfo
->lc_handle
[MSVCRT_LC_COLLATE
];
1007 locinfo
->lc_id
[MSVCRT_LC_COLLATE
].wCodePage
= old_locinfo
->lc_id
[MSVCRT_LC_COLLATE
].wCodePage
;
1008 } else if(lcid
[MSVCRT_LC_COLLATE
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_COLLATE
)) {
1009 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_COLLATE
],
1010 cp
[MSVCRT_LC_COLLATE
], locinfo
, MSVCRT_LC_COLLATE
)) {
1011 free_locinfo(locinfo
);
1015 locinfo
->lc_collate_cp
= locinfo
->lc_id
[MSVCRT_LC_COLLATE
].wCodePage
;
1017 if(!set_lc_locale_name(locinfo
, MSVCRT_LC_COLLATE
)) {
1018 free_locinfo(locinfo
);
1022 locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
= MSVCRT__strdup("C");
1024 if(!category_needs_update(MSVCRT_LC_CTYPE
, category
, old_locinfo
,
1025 lcid
[MSVCRT_LC_CTYPE
], cp
[MSVCRT_LC_CTYPE
])) {
1026 locinfo
->lc_handle
[MSVCRT_LC_CTYPE
] = old_locinfo
->lc_handle
[MSVCRT_LC_CTYPE
];
1027 locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
= old_locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
;
1028 } else if(lcid
[MSVCRT_LC_CTYPE
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_CTYPE
)) {
1032 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_CTYPE
],
1033 cp
[MSVCRT_LC_CTYPE
], locinfo
, MSVCRT_LC_CTYPE
)) {
1034 free_locinfo(locinfo
);
1038 locinfo
->lc_codepage
= locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
;
1039 locinfo
->lc_clike
= 1;
1040 if(!GetCPInfo(locinfo
->lc_codepage
, &cp_info
)) {
1041 free_locinfo(locinfo
);
1044 locinfo
->mb_cur_max
= cp_info
.MaxCharSize
;
1046 locinfo
->ctype1_refcount
= MSVCRT_malloc(sizeof(int));
1047 locinfo
->ctype1
= MSVCRT_malloc(sizeof(short[257]));
1048 if(!locinfo
->ctype1_refcount
|| !locinfo
->ctype1
) {
1049 free_locinfo(locinfo
);
1053 *locinfo
->ctype1_refcount
= 1;
1054 locinfo
->ctype1
[0] = 0;
1055 locinfo
->pctype
= locinfo
->ctype1
+1;
1057 buf
[1] = buf
[2] = '\0';
1058 for(i
=1; i
<257; i
++) {
1061 /* builtin GetStringTypeA doesn't set output to 0 on invalid input */
1062 locinfo
->ctype1
[i
] = 0;
1064 GetStringTypeA(lcid
[MSVCRT_LC_CTYPE
], CT_CTYPE1
, buf
,
1065 1, locinfo
->ctype1
+i
);
1068 for(i
=0; cp_info
.LeadByte
[i
+1]!=0; i
+=2)
1069 for(j
=cp_info
.LeadByte
[i
]; j
<=cp_info
.LeadByte
[i
+1]; j
++)
1070 locinfo
->ctype1
[j
+1] |= MSVCRT__LEADBYTE
;
1072 if(!set_lc_locale_name(locinfo
, MSVCRT_LC_CTYPE
)) {
1073 free_locinfo(locinfo
);
1077 for(i
=0; i
<256; i
++) {
1078 if(locinfo
->pctype
[i
] & MSVCRT__LEADBYTE
)
1084 LCMapStringA(lcid
[MSVCRT_LC_CTYPE
], LCMAP_LOWERCASE
, buf
, 256,
1085 (char*)locinfo
->pclmap
, 256);
1086 LCMapStringA(lcid
[MSVCRT_LC_CTYPE
], LCMAP_UPPERCASE
, buf
, 256,
1087 (char*)locinfo
->pcumap
, 256);
1089 locinfo
->lc_clike
= 1;
1090 locinfo
->mb_cur_max
= 1;
1091 locinfo
->pctype
= MSVCRT__ctype
+1;
1092 locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
= MSVCRT__strdup("C");
1094 for(i
=0; i
<256; i
++) {
1095 if(locinfo
->pctype
[i
] & MSVCRT__LEADBYTE
)
1101 for(i
=0; i
<256; i
++) {
1102 locinfo
->pclmap
[i
] = (i
>='A' && i
<='Z' ? i
-'A'+'a' : i
);
1103 locinfo
->pcumap
[i
] = (i
>='a' && i
<='z' ? i
-'a'+'A' : i
);
1107 if(!category_needs_update(MSVCRT_LC_MONETARY
, category
, old_locinfo
,
1108 lcid
[MSVCRT_LC_MONETARY
], cp
[MSVCRT_LC_MONETARY
])) {
1109 locinfo
->lc_handle
[MSVCRT_LC_MONETARY
] = old_locinfo
->lc_handle
[MSVCRT_LC_MONETARY
];
1110 locinfo
->lc_id
[MSVCRT_LC_MONETARY
].wCodePage
= old_locinfo
->lc_id
[MSVCRT_LC_MONETARY
].wCodePage
;
1111 } else if(lcid
[MSVCRT_LC_MONETARY
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_MONETARY
)) {
1112 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_MONETARY
],
1113 cp
[MSVCRT_LC_MONETARY
], locinfo
, MSVCRT_LC_MONETARY
)) {
1114 free_locinfo(locinfo
);
1118 locinfo
->lconv_intl_refcount
= MSVCRT_malloc(sizeof(int));
1119 locinfo
->lconv_mon_refcount
= MSVCRT_malloc(sizeof(int));
1120 if(!locinfo
->lconv_intl_refcount
|| !locinfo
->lconv_mon_refcount
) {
1121 free_locinfo(locinfo
);
1125 *locinfo
->lconv_intl_refcount
= 1;
1126 *locinfo
->lconv_mon_refcount
= 1;
1128 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SINTLSYMBOL
1129 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1130 if(i
&& (locinfo
->lconv
->int_curr_symbol
= MSVCRT_malloc(i
)))
1131 memcpy(locinfo
->lconv
->int_curr_symbol
, buf
, i
);
1133 free_locinfo(locinfo
);
1137 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SCURRENCY
1138 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1139 if(i
&& (locinfo
->lconv
->currency_symbol
= MSVCRT_malloc(i
)))
1140 memcpy(locinfo
->lconv
->currency_symbol
, buf
, i
);
1142 free_locinfo(locinfo
);
1146 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONDECIMALSEP
1147 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1148 if(i
&& (locinfo
->lconv
->mon_decimal_point
= MSVCRT_malloc(i
)))
1149 memcpy(locinfo
->lconv
->mon_decimal_point
, buf
, i
);
1151 free_locinfo(locinfo
);
1155 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONTHOUSANDSEP
1156 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1157 if(i
&& (locinfo
->lconv
->mon_thousands_sep
= MSVCRT_malloc(i
)))
1158 memcpy(locinfo
->lconv
->mon_thousands_sep
, buf
, i
);
1160 free_locinfo(locinfo
);
1164 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONGROUPING
1165 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1167 i
= i
/2 + (buf
[i
-2]=='0'?0:1);
1168 if(i
&& (locinfo
->lconv
->mon_grouping
= MSVCRT_malloc(i
))) {
1169 for(i
=0; buf
[i
+1]==';'; i
+=2)
1170 locinfo
->lconv
->mon_grouping
[i
/2] = buf
[i
]-'0';
1171 locinfo
->lconv
->mon_grouping
[i
/2] = buf
[i
]-'0';
1173 locinfo
->lconv
->mon_grouping
[i
/2+1] = 127;
1175 free_locinfo(locinfo
);
1179 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SPOSITIVESIGN
1180 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1181 if(i
&& (locinfo
->lconv
->positive_sign
= MSVCRT_malloc(i
)))
1182 memcpy(locinfo
->lconv
->positive_sign
, buf
, i
);
1184 free_locinfo(locinfo
);
1188 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SNEGATIVESIGN
1189 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1190 if(i
&& (locinfo
->lconv
->negative_sign
= MSVCRT_malloc(i
)))
1191 memcpy(locinfo
->lconv
->negative_sign
, buf
, i
);
1193 free_locinfo(locinfo
);
1197 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IINTLCURRDIGITS
1198 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1199 locinfo
->lconv
->int_frac_digits
= atoi(buf
);
1201 free_locinfo(locinfo
);
1205 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_ICURRDIGITS
1206 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1207 locinfo
->lconv
->frac_digits
= atoi(buf
);
1209 free_locinfo(locinfo
);
1213 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSYMPRECEDES
1214 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1215 locinfo
->lconv
->p_cs_precedes
= atoi(buf
);
1217 free_locinfo(locinfo
);
1221 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSEPBYSPACE
1222 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1223 locinfo
->lconv
->p_sep_by_space
= atoi(buf
);
1225 free_locinfo(locinfo
);
1229 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSYMPRECEDES
1230 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1231 locinfo
->lconv
->n_cs_precedes
= atoi(buf
);
1233 free_locinfo(locinfo
);
1237 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSEPBYSPACE
1238 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1239 locinfo
->lconv
->n_sep_by_space
= atoi(buf
);
1241 free_locinfo(locinfo
);
1245 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSIGNPOSN
1246 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1247 locinfo
->lconv
->p_sign_posn
= atoi(buf
);
1249 free_locinfo(locinfo
);
1253 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSIGNPOSN
1254 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1255 locinfo
->lconv
->n_sign_posn
= atoi(buf
);
1257 free_locinfo(locinfo
);
1261 #if _MSVCR_VER >= 100
1262 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SINTLSYMBOL
1263 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1264 if(i
&& (locinfo
->lconv
->_W_int_curr_symbol
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1265 memcpy(locinfo
->lconv
->_W_int_curr_symbol
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1267 free_locinfo(locinfo
);
1271 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SCURRENCY
1272 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1273 if(i
&& (locinfo
->lconv
->_W_currency_symbol
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1274 memcpy(locinfo
->lconv
->_W_currency_symbol
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1276 free_locinfo(locinfo
);
1280 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONDECIMALSEP
1281 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1282 if(i
&& (locinfo
->lconv
->_W_mon_decimal_point
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1283 memcpy(locinfo
->lconv
->_W_mon_decimal_point
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1285 free_locinfo(locinfo
);
1289 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONTHOUSANDSEP
1290 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1291 if(i
&& (locinfo
->lconv
->_W_mon_thousands_sep
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1292 memcpy(locinfo
->lconv
->_W_mon_thousands_sep
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1294 free_locinfo(locinfo
);
1298 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SPOSITIVESIGN
1299 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1300 if(i
&& (locinfo
->lconv
->_W_positive_sign
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1301 memcpy(locinfo
->lconv
->_W_positive_sign
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1303 free_locinfo(locinfo
);
1307 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SNEGATIVESIGN
1308 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1309 if(i
&& (locinfo
->lconv
->_W_negative_sign
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1310 memcpy(locinfo
->lconv
->_W_negative_sign
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1312 free_locinfo(locinfo
);
1317 if(!set_lc_locale_name(locinfo
, MSVCRT_LC_MONETARY
)) {
1318 free_locinfo(locinfo
);
1322 locinfo
->lconv
->int_curr_symbol
= MSVCRT_malloc(sizeof(char));
1323 locinfo
->lconv
->currency_symbol
= MSVCRT_malloc(sizeof(char));
1324 locinfo
->lconv
->mon_decimal_point
= MSVCRT_malloc(sizeof(char));
1325 locinfo
->lconv
->mon_thousands_sep
= MSVCRT_malloc(sizeof(char));
1326 locinfo
->lconv
->mon_grouping
= MSVCRT_malloc(sizeof(char));
1327 locinfo
->lconv
->positive_sign
= MSVCRT_malloc(sizeof(char));
1328 locinfo
->lconv
->negative_sign
= MSVCRT_malloc(sizeof(char));
1330 if(!locinfo
->lconv
->int_curr_symbol
|| !locinfo
->lconv
->currency_symbol
1331 || !locinfo
->lconv
->mon_decimal_point
|| !locinfo
->lconv
->mon_thousands_sep
1332 || !locinfo
->lconv
->mon_grouping
|| !locinfo
->lconv
->positive_sign
1333 || !locinfo
->lconv
->negative_sign
) {
1334 free_locinfo(locinfo
);
1338 locinfo
->lconv
->int_curr_symbol
[0] = '\0';
1339 locinfo
->lconv
->currency_symbol
[0] = '\0';
1340 locinfo
->lconv
->mon_decimal_point
[0] = '\0';
1341 locinfo
->lconv
->mon_thousands_sep
[0] = '\0';
1342 locinfo
->lconv
->mon_grouping
[0] = '\0';
1343 locinfo
->lconv
->positive_sign
[0] = '\0';
1344 locinfo
->lconv
->negative_sign
[0] = '\0';
1345 locinfo
->lconv
->int_frac_digits
= 127;
1346 locinfo
->lconv
->frac_digits
= 127;
1347 locinfo
->lconv
->p_cs_precedes
= 127;
1348 locinfo
->lconv
->p_sep_by_space
= 127;
1349 locinfo
->lconv
->n_cs_precedes
= 127;
1350 locinfo
->lconv
->n_sep_by_space
= 127;
1351 locinfo
->lconv
->p_sign_posn
= 127;
1352 locinfo
->lconv
->n_sign_posn
= 127;
1354 #if _MSVCR_VER >= 100
1355 locinfo
->lconv
->_W_int_curr_symbol
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1356 locinfo
->lconv
->_W_currency_symbol
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1357 locinfo
->lconv
->_W_mon_decimal_point
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1358 locinfo
->lconv
->_W_mon_thousands_sep
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1359 locinfo
->lconv
->_W_positive_sign
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1360 locinfo
->lconv
->_W_negative_sign
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1362 if(!locinfo
->lconv
->_W_int_curr_symbol
|| !locinfo
->lconv
->_W_currency_symbol
1363 || !locinfo
->lconv
->_W_mon_decimal_point
|| !locinfo
->lconv
->_W_mon_thousands_sep
1364 || !locinfo
->lconv
->positive_sign
|| !locinfo
->lconv
->negative_sign
) {
1365 free_locinfo(locinfo
);
1369 locinfo
->lconv
->_W_int_curr_symbol
[0] = '\0';
1370 locinfo
->lconv
->_W_currency_symbol
[0] = '\0';
1371 locinfo
->lconv
->_W_mon_decimal_point
[0] = '\0';
1372 locinfo
->lconv
->_W_mon_thousands_sep
[0] = '\0';
1373 locinfo
->lconv
->_W_positive_sign
[0] = '\0';
1374 locinfo
->lconv
->_W_negative_sign
[0] = '\0';
1377 locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
= MSVCRT__strdup("C");
1380 if(!category_needs_update(MSVCRT_LC_NUMERIC
, category
, old_locinfo
,
1381 lcid
[MSVCRT_LC_NUMERIC
], cp
[MSVCRT_LC_NUMERIC
])) {
1382 locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
] = old_locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
];
1383 locinfo
->lc_id
[MSVCRT_LC_NUMERIC
].wCodePage
= old_locinfo
->lc_id
[MSVCRT_LC_NUMERIC
].wCodePage
;
1384 } else if(lcid
[MSVCRT_LC_NUMERIC
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_NUMERIC
)) {
1385 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_NUMERIC
],
1386 cp
[MSVCRT_LC_NUMERIC
], locinfo
, MSVCRT_LC_NUMERIC
)) {
1387 free_locinfo(locinfo
);
1391 if(!locinfo
->lconv_intl_refcount
)
1392 locinfo
->lconv_intl_refcount
= MSVCRT_malloc(sizeof(int));
1393 locinfo
->lconv_num_refcount
= MSVCRT_malloc(sizeof(int));
1394 if(!locinfo
->lconv_intl_refcount
|| !locinfo
->lconv_num_refcount
) {
1395 free_locinfo(locinfo
);
1399 *locinfo
->lconv_intl_refcount
= 1;
1400 *locinfo
->lconv_num_refcount
= 1;
1402 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SDECIMAL
1403 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1404 if(i
&& (locinfo
->lconv
->decimal_point
= MSVCRT_malloc(i
)))
1405 memcpy(locinfo
->lconv
->decimal_point
, buf
, i
);
1407 free_locinfo(locinfo
);
1411 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_STHOUSAND
1412 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1413 if(i
&& (locinfo
->lconv
->thousands_sep
= MSVCRT_malloc(i
)))
1414 memcpy(locinfo
->lconv
->thousands_sep
, buf
, i
);
1416 free_locinfo(locinfo
);
1420 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SGROUPING
1421 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1423 i
= i
/2 + (buf
[i
-2]=='0'?0:1);
1424 if(i
&& (locinfo
->lconv
->grouping
= MSVCRT_malloc(i
))) {
1425 for(i
=0; buf
[i
+1]==';'; i
+=2)
1426 locinfo
->lconv
->grouping
[i
/2] = buf
[i
]-'0';
1427 locinfo
->lconv
->grouping
[i
/2] = buf
[i
]-'0';
1429 locinfo
->lconv
->grouping
[i
/2+1] = 127;
1431 free_locinfo(locinfo
);
1435 #if _MSVCR_VER >= 100
1436 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SDECIMAL
1437 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1438 if(i
&& (locinfo
->lconv
->_W_decimal_point
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1439 memcpy(locinfo
->lconv
->_W_decimal_point
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1441 free_locinfo(locinfo
);
1445 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_STHOUSAND
1446 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1447 if(i
&& (locinfo
->lconv
->_W_thousands_sep
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1448 memcpy(locinfo
->lconv
->_W_thousands_sep
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1450 free_locinfo(locinfo
);
1455 if(!set_lc_locale_name(locinfo
, MSVCRT_LC_NUMERIC
)) {
1456 free_locinfo(locinfo
);
1460 locinfo
->lconv
->decimal_point
= MSVCRT_malloc(sizeof(char[2]));
1461 locinfo
->lconv
->thousands_sep
= MSVCRT_malloc(sizeof(char));
1462 locinfo
->lconv
->grouping
= MSVCRT_malloc(sizeof(char));
1463 if(!locinfo
->lconv
->decimal_point
|| !locinfo
->lconv
->thousands_sep
1464 || !locinfo
->lconv
->grouping
) {
1465 free_locinfo(locinfo
);
1469 locinfo
->lconv
->decimal_point
[0] = '.';
1470 locinfo
->lconv
->decimal_point
[1] = '\0';
1471 locinfo
->lconv
->thousands_sep
[0] = '\0';
1472 locinfo
->lconv
->grouping
[0] = '\0';
1474 #if _MSVCR_VER >= 100
1475 locinfo
->lconv
->_W_decimal_point
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
[2]));
1476 locinfo
->lconv
->_W_thousands_sep
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1478 if(!locinfo
->lconv
->_W_decimal_point
|| !locinfo
->lconv
->_W_thousands_sep
) {
1479 free_locinfo(locinfo
);
1483 locinfo
->lconv
->_W_decimal_point
[0] = '.';
1484 locinfo
->lconv
->_W_decimal_point
[1] = '\0';
1485 locinfo
->lconv
->_W_thousands_sep
[0] = '\0';
1488 locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
= MSVCRT__strdup("C");
1491 if(!category_needs_update(MSVCRT_LC_TIME
, category
, old_locinfo
,
1492 lcid
[MSVCRT_LC_TIME
], cp
[MSVCRT_LC_TIME
])) {
1493 locinfo
->lc_handle
[MSVCRT_LC_TIME
] = old_locinfo
->lc_handle
[MSVCRT_LC_TIME
];
1494 locinfo
->lc_id
[MSVCRT_LC_TIME
].wCodePage
= old_locinfo
->lc_id
[MSVCRT_LC_TIME
].wCodePage
;
1496 if(lcid
[MSVCRT_LC_TIME
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_TIME
)) {
1497 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_TIME
],
1498 cp
[MSVCRT_LC_TIME
], locinfo
, MSVCRT_LC_TIME
)) {
1499 free_locinfo(locinfo
);
1503 if(!set_lc_locale_name(locinfo
, MSVCRT_LC_TIME
)) {
1504 free_locinfo(locinfo
);
1508 locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
= MSVCRT__strdup("C");
1510 size
= sizeof(MSVCRT___lc_time_data
);
1511 lcid_tmp
= lcid
[MSVCRT_LC_TIME
] ? lcid
[MSVCRT_LC_TIME
] : MAKELCID(LANG_ENGLISH
, SORT_DEFAULT
);
1512 for(i
=0; i
<sizeof(time_data
)/sizeof(time_data
[0]); i
++) {
1513 if(time_data
[i
]==LOCALE_SSHORTDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1514 size
+= sizeof(cloc_short_date
) + sizeof(cloc_short_dateW
);
1515 }else if(time_data
[i
]==LOCALE_SLONGDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1516 size
+= sizeof(cloc_long_date
) + sizeof(cloc_long_dateW
);
1518 ret
= GetLocaleInfoA(lcid_tmp
, time_data
[i
]
1519 |LOCALE_NOUSEROVERRIDE
, NULL
, 0);
1521 free_locinfo(locinfo
);
1526 ret
= GetLocaleInfoW(lcid_tmp
, time_data
[i
]
1527 |LOCALE_NOUSEROVERRIDE
, NULL
, 0);
1529 free_locinfo(locinfo
);
1532 size
+= ret
*sizeof(MSVCRT_wchar_t
);
1535 #if _MSVCR_VER >= 110
1536 size
+= LCIDToLocaleName(lcid
[MSVCRT_LC_TIME
], NULL
, 0, 0)*sizeof(MSVCRT_wchar_t
);
1539 locinfo
->lc_time_curr
= MSVCRT_malloc(size
);
1540 if(!locinfo
->lc_time_curr
) {
1541 free_locinfo(locinfo
);
1546 for(i
=0; i
<sizeof(time_data
)/sizeof(time_data
[0]); i
++) {
1547 locinfo
->lc_time_curr
->str
.str
[i
] = &locinfo
->lc_time_curr
->data
[ret
];
1548 if(time_data
[i
]==LOCALE_SSHORTDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1549 memcpy(&locinfo
->lc_time_curr
->data
[ret
], cloc_short_date
, sizeof(cloc_short_date
));
1550 ret
+= sizeof(cloc_short_date
);
1551 }else if(time_data
[i
]==LOCALE_SLONGDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1552 memcpy(&locinfo
->lc_time_curr
->data
[ret
], cloc_long_date
, sizeof(cloc_long_date
));
1553 ret
+= sizeof(cloc_long_date
);
1554 }else if(time_data
[i
]==LOCALE_STIMEFORMAT
&& !lcid
[MSVCRT_LC_TIME
]) {
1555 memcpy(&locinfo
->lc_time_curr
->data
[ret
], cloc_time
, sizeof(cloc_time
));
1556 ret
+= sizeof(cloc_time
);
1558 ret
+= GetLocaleInfoA(lcid_tmp
, time_data
[i
]|LOCALE_NOUSEROVERRIDE
,
1559 &locinfo
->lc_time_curr
->data
[ret
], size
-ret
);
1562 for(i
=0; i
<sizeof(time_data
)/sizeof(time_data
[0]); i
++) {
1563 locinfo
->lc_time_curr
->wstr
.wstr
[i
] = (MSVCRT_wchar_t
*)&locinfo
->lc_time_curr
->data
[ret
];
1564 if(time_data
[i
]==LOCALE_SSHORTDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1565 memcpy(&locinfo
->lc_time_curr
->data
[ret
], cloc_short_dateW
, sizeof(cloc_short_dateW
));
1566 ret
+= sizeof(cloc_short_dateW
);
1567 }else if(time_data
[i
]==LOCALE_SLONGDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1568 memcpy(&locinfo
->lc_time_curr
->data
[ret
], cloc_long_dateW
, sizeof(cloc_long_dateW
));
1569 ret
+= sizeof(cloc_long_dateW
);
1570 }else if(time_data
[i
]==LOCALE_STIMEFORMAT
&& !lcid
[MSVCRT_LC_TIME
]) {
1571 memcpy(&locinfo
->lc_time_curr
->data
[ret
], cloc_timeW
, sizeof(cloc_timeW
));
1572 ret
+= sizeof(cloc_timeW
);
1574 ret
+= GetLocaleInfoW(lcid_tmp
, time_data
[i
]|LOCALE_NOUSEROVERRIDE
,
1575 (MSVCRT_wchar_t
*)&locinfo
->lc_time_curr
->data
[ret
], size
-ret
)*sizeof(MSVCRT_wchar_t
);
1578 #if _MSVCR_VER >= 110
1579 locinfo
->lc_time_curr
->locname
= (MSVCRT_wchar_t
*)&locinfo
->lc_time_curr
->data
[ret
];
1580 LCIDToLocaleName(lcid
[MSVCRT_LC_TIME
], locinfo
->lc_time_curr
->locname
,
1581 (size
-ret
)/sizeof(MSVCRT_wchar_t
), 0);
1583 locinfo
->lc_time_curr
->lcid
= lcid
[MSVCRT_LC_TIME
];
1590 /*********************************************************************
1591 * _lock_locales (UCRTBASE.@)
1593 void CDECL
_lock_locales(void)
1595 _mlock(_SETLOCALE_LOCK
);
1598 /*********************************************************************
1599 * _unlock_locales (UCRTBASE.@)
1601 void CDECL
_unlock_locales(void)
1603 _munlock(_SETLOCALE_LOCK
);
1606 /*********************************************************************
1607 * _create_locale (MSVCRT.@)
1609 MSVCRT__locale_t CDECL
MSVCRT__create_locale(int category
, const char *locale
)
1611 MSVCRT__locale_t loc
;
1613 loc
= MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct
));
1617 loc
->locinfo
= create_locinfo(category
, locale
, NULL
);
1623 loc
->mbcinfo
= MSVCRT_malloc(sizeof(MSVCRT_threadmbcinfo
));
1625 free_locinfo(loc
->locinfo
);
1630 loc
->mbcinfo
->refcount
= 1;
1631 _setmbcp_l(loc
->locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
,
1632 loc
->locinfo
->lc_handle
[MSVCRT_LC_CTYPE
], loc
->mbcinfo
);
1636 /*********************************************************************
1637 * _wcreate_locale (MSVCRT.@)
1639 MSVCRT__locale_t CDECL
MSVCRT__wcreate_locale(int category
, const MSVCRT_wchar_t
*locale
)
1641 MSVCRT__locale_t loc
;
1645 if(category
<MSVCRT_LC_MIN
|| category
>MSVCRT_LC_MAX
|| !locale
)
1648 len
= MSVCRT_wcstombs(NULL
, locale
, 0);
1651 if(!(str
= MSVCRT_malloc(++len
)))
1653 MSVCRT_wcstombs(str
, locale
, len
);
1655 loc
= MSVCRT__create_locale(category
, str
);
1661 /*********************************************************************
1662 * setlocale (MSVCRT.@)
1664 char* CDECL
MSVCRT_setlocale(int category
, const char* locale
)
1666 MSVCRT_pthreadlocinfo locinfo
= get_locinfo();
1667 MSVCRT_pthreadlocinfo newlocinfo
;
1669 if(category
<MSVCRT_LC_MIN
|| category
>MSVCRT_LC_MAX
)
1673 if(category
== MSVCRT_LC_ALL
)
1674 return construct_lc_all(locinfo
);
1676 return locinfo
->lc_category
[category
].locale
;
1679 newlocinfo
= create_locinfo(category
, locale
, locinfo
);
1681 WARN("%d %s failed\n", category
, locale
);
1687 if(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
]!=newlocinfo
->lc_handle
[MSVCRT_LC_COLLATE
]
1688 || locinfo
->lc_id
[MSVCRT_LC_COLLATE
].wCodePage
!=newlocinfo
->lc_id
[MSVCRT_LC_COLLATE
].wCodePage
) {
1689 locinfo
->lc_collate_cp
= newlocinfo
->lc_collate_cp
;
1690 locinfo
->lc_handle
[MSVCRT_LC_COLLATE
] =
1691 newlocinfo
->lc_handle
[MSVCRT_LC_COLLATE
];
1692 locinfo
->lc_id
[MSVCRT_LC_COLLATE
] =
1693 newlocinfo
->lc_id
[MSVCRT_LC_COLLATE
];
1694 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
,
1695 (void**)&newlocinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
);
1696 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_COLLATE
].refcount
,
1697 (void**)&newlocinfo
->lc_category
[MSVCRT_LC_COLLATE
].refcount
);
1699 #if _MSVCR_VER >= 110
1700 swap_pointers((void**)&locinfo
->lc_name
[MSVCRT_LC_COLLATE
],
1701 (void**)&newlocinfo
->lc_name
[MSVCRT_LC_COLLATE
]);
1705 if(locinfo
->lc_handle
[MSVCRT_LC_CTYPE
]!=newlocinfo
->lc_handle
[MSVCRT_LC_CTYPE
]
1706 || locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
!=newlocinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
) {
1707 locinfo
->lc_handle
[MSVCRT_LC_CTYPE
] =
1708 newlocinfo
->lc_handle
[MSVCRT_LC_CTYPE
];
1709 locinfo
->lc_id
[MSVCRT_LC_CTYPE
] =
1710 newlocinfo
->lc_id
[MSVCRT_LC_CTYPE
];
1711 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
,
1712 (void**)&newlocinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
);
1713 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_CTYPE
].refcount
,
1714 (void**)&newlocinfo
->lc_category
[MSVCRT_LC_CTYPE
].refcount
);
1716 locinfo
->lc_codepage
= newlocinfo
->lc_codepage
;
1717 locinfo
->lc_clike
= newlocinfo
->lc_clike
;
1718 locinfo
->mb_cur_max
= newlocinfo
->mb_cur_max
;
1720 swap_pointers((void**)&locinfo
->ctype1_refcount
,
1721 (void**)&newlocinfo
->ctype1_refcount
);
1722 swap_pointers((void**)&locinfo
->ctype1
, (void**)&newlocinfo
->ctype1
);
1723 swap_pointers((void**)&locinfo
->pctype
, (void**)&newlocinfo
->pctype
);
1724 swap_pointers((void**)&locinfo
->pclmap
, (void**)&newlocinfo
->pclmap
);
1725 swap_pointers((void**)&locinfo
->pcumap
, (void**)&newlocinfo
->pcumap
);
1727 #if _MSVCR_VER >= 110
1728 swap_pointers((void**)&locinfo
->lc_name
[MSVCRT_LC_CTYPE
],
1729 (void**)&newlocinfo
->lc_name
[MSVCRT_LC_CTYPE
]);
1733 if(locinfo
->lc_handle
[MSVCRT_LC_MONETARY
]!=newlocinfo
->lc_handle
[MSVCRT_LC_MONETARY
]
1734 || locinfo
->lc_id
[MSVCRT_LC_MONETARY
].wCodePage
!=newlocinfo
->lc_id
[MSVCRT_LC_MONETARY
].wCodePage
) {
1735 locinfo
->lc_handle
[MSVCRT_LC_MONETARY
] =
1736 newlocinfo
->lc_handle
[MSVCRT_LC_MONETARY
];
1737 locinfo
->lc_id
[MSVCRT_LC_MONETARY
] =
1738 newlocinfo
->lc_id
[MSVCRT_LC_MONETARY
];
1739 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
,
1740 (void**)&newlocinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
);
1741 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_MONETARY
].refcount
,
1742 (void**)&newlocinfo
->lc_category
[MSVCRT_LC_MONETARY
].refcount
);
1744 swap_pointers((void**)&locinfo
->lconv
->int_curr_symbol
,
1745 (void**)&newlocinfo
->lconv
->int_curr_symbol
);
1746 swap_pointers((void**)&locinfo
->lconv
->currency_symbol
,
1747 (void**)&newlocinfo
->lconv
->currency_symbol
);
1748 swap_pointers((void**)&locinfo
->lconv
->mon_decimal_point
,
1749 (void**)&newlocinfo
->lconv
->mon_decimal_point
);
1750 swap_pointers((void**)&locinfo
->lconv
->mon_thousands_sep
,
1751 (void**)&newlocinfo
->lconv
->mon_thousands_sep
);
1752 swap_pointers((void**)&locinfo
->lconv
->mon_grouping
,
1753 (void**)&newlocinfo
->lconv
->mon_grouping
);
1754 swap_pointers((void**)&locinfo
->lconv
->positive_sign
,
1755 (void**)&newlocinfo
->lconv
->positive_sign
);
1756 swap_pointers((void**)&locinfo
->lconv
->negative_sign
,
1757 (void**)&newlocinfo
->lconv
->negative_sign
);
1759 #if _MSVCR_VER >= 100
1760 swap_pointers((void**)&locinfo
->lconv
->_W_int_curr_symbol
,
1761 (void**)&newlocinfo
->lconv
->_W_int_curr_symbol
);
1762 swap_pointers((void**)&locinfo
->lconv
->_W_currency_symbol
,
1763 (void**)&newlocinfo
->lconv
->_W_currency_symbol
);
1764 swap_pointers((void**)&locinfo
->lconv
->_W_mon_decimal_point
,
1765 (void**)&newlocinfo
->lconv
->_W_mon_decimal_point
);
1766 swap_pointers((void**)&locinfo
->lconv
->_W_mon_thousands_sep
,
1767 (void**)&newlocinfo
->lconv
->_W_mon_thousands_sep
);
1768 swap_pointers((void**)&locinfo
->lconv
->_W_positive_sign
,
1769 (void**)&newlocinfo
->lconv
->_W_positive_sign
);
1770 swap_pointers((void**)&locinfo
->lconv
->_W_negative_sign
,
1771 (void**)&newlocinfo
->lconv
->_W_negative_sign
);
1774 locinfo
->lconv
->int_frac_digits
= newlocinfo
->lconv
->int_frac_digits
;
1775 locinfo
->lconv
->frac_digits
= newlocinfo
->lconv
->frac_digits
;
1776 locinfo
->lconv
->p_cs_precedes
= newlocinfo
->lconv
->p_cs_precedes
;
1777 locinfo
->lconv
->p_sep_by_space
= newlocinfo
->lconv
->p_sep_by_space
;
1778 locinfo
->lconv
->n_cs_precedes
= newlocinfo
->lconv
->n_cs_precedes
;
1779 locinfo
->lconv
->n_sep_by_space
= newlocinfo
->lconv
->n_sep_by_space
;
1780 locinfo
->lconv
->p_sign_posn
= newlocinfo
->lconv
->p_sign_posn
;
1781 locinfo
->lconv
->n_sign_posn
= newlocinfo
->lconv
->n_sign_posn
;
1783 #if _MSVCR_VER >= 110
1784 swap_pointers((void**)&locinfo
->lc_name
[MSVCRT_LC_MONETARY
],
1785 (void**)&newlocinfo
->lc_name
[MSVCRT_LC_MONETARY
]);
1789 if(locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
]!=newlocinfo
->lc_handle
[MSVCRT_LC_NUMERIC
]
1790 || locinfo
->lc_id
[MSVCRT_LC_NUMERIC
].wCodePage
!=newlocinfo
->lc_id
[MSVCRT_LC_NUMERIC
].wCodePage
) {
1791 locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
] =
1792 newlocinfo
->lc_handle
[MSVCRT_LC_NUMERIC
];
1793 locinfo
->lc_id
[MSVCRT_LC_NUMERIC
] =
1794 newlocinfo
->lc_id
[MSVCRT_LC_NUMERIC
];
1795 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
,
1796 (void**)&newlocinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
);
1797 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].refcount
,
1798 (void**)&newlocinfo
->lc_category
[MSVCRT_LC_NUMERIC
].refcount
);
1800 swap_pointers((void**)&locinfo
->lconv
->decimal_point
,
1801 (void**)&newlocinfo
->lconv
->decimal_point
);
1802 swap_pointers((void**)&locinfo
->lconv
->thousands_sep
,
1803 (void**)&newlocinfo
->lconv
->thousands_sep
);
1804 swap_pointers((void**)&locinfo
->lconv
->grouping
,
1805 (void**)&newlocinfo
->lconv
->grouping
);
1807 #if _MSVCR_VER >= 100
1808 swap_pointers((void**)&locinfo
->lconv
->_W_decimal_point
,
1809 (void**)&newlocinfo
->lconv
->_W_decimal_point
);
1810 swap_pointers((void**)&locinfo
->lconv
->_W_thousands_sep
,
1811 (void**)&newlocinfo
->lconv
->_W_thousands_sep
);
1814 #if _MSVCR_VER >= 110
1815 swap_pointers((void**)&locinfo
->lc_name
[MSVCRT_LC_NUMERIC
],
1816 (void**)&newlocinfo
->lc_name
[MSVCRT_LC_NUMERIC
]);
1820 if(locinfo
->lc_handle
[MSVCRT_LC_TIME
]!=newlocinfo
->lc_handle
[MSVCRT_LC_TIME
]
1821 || locinfo
->lc_id
[MSVCRT_LC_TIME
].wCodePage
!=newlocinfo
->lc_id
[MSVCRT_LC_TIME
].wCodePage
) {
1822 locinfo
->lc_handle
[MSVCRT_LC_TIME
] =
1823 newlocinfo
->lc_handle
[MSVCRT_LC_TIME
];
1824 locinfo
->lc_id
[MSVCRT_LC_TIME
] =
1825 newlocinfo
->lc_id
[MSVCRT_LC_TIME
];
1826 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
,
1827 (void**)&newlocinfo
->lc_category
[MSVCRT_LC_TIME
].locale
);
1828 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_TIME
].refcount
,
1829 (void**)&newlocinfo
->lc_category
[MSVCRT_LC_TIME
].refcount
);
1830 swap_pointers((void**)&locinfo
->lc_time_curr
,
1831 (void**)&newlocinfo
->lc_time_curr
);
1833 #if _MSVCR_VER >= 110
1834 swap_pointers((void**)&locinfo
->lc_name
[MSVCRT_LC_TIME
],
1835 (void**)&newlocinfo
->lc_name
[MSVCRT_LC_TIME
]);
1839 free_locinfo(newlocinfo
);
1842 if(locinfo
== MSVCRT_locale
->locinfo
) {
1845 MSVCRT___lc_codepage
= locinfo
->lc_codepage
;
1846 MSVCRT___lc_collate_cp
= locinfo
->lc_collate_cp
;
1847 MSVCRT___mb_cur_max
= locinfo
->mb_cur_max
;
1848 MSVCRT__pctype
= locinfo
->pctype
;
1849 for(i
=MSVCRT_LC_MIN
; i
<=MSVCRT_LC_MAX
; i
++)
1850 MSVCRT___lc_handle
[i
] = MSVCRT_locale
->locinfo
->lc_handle
[i
];
1853 if(category
== MSVCRT_LC_ALL
)
1854 return construct_lc_all(locinfo
);
1856 return locinfo
->lc_category
[category
].locale
;
1859 /*********************************************************************
1860 * _wsetlocale (MSVCRT.@)
1862 MSVCRT_wchar_t
* CDECL
MSVCRT__wsetlocale(int category
, const MSVCRT_wchar_t
* wlocale
)
1864 static MSVCRT_wchar_t current_lc_all
[MAX_LOCALE_LENGTH
];
1866 char *locale
= NULL
;
1871 len
= MSVCRT_wcstombs(NULL
, wlocale
, 0);
1875 locale
= MSVCRT_malloc(++len
);
1879 MSVCRT_wcstombs(locale
, wlocale
, len
);
1883 ret
= MSVCRT_setlocale(category
, locale
);
1884 MSVCRT_free(locale
);
1886 if(ret
&& MSVCRT_mbstowcs(current_lc_all
, ret
, MAX_LOCALE_LENGTH
)==-1)
1890 return ret
? current_lc_all
: NULL
;
1893 /*********************************************************************
1894 * _configthreadlocale (MSVCR80.@)
1896 int CDECL
_configthreadlocale(int type
)
1898 thread_data_t
*data
= msvcrt_get_thread_data();
1899 MSVCRT__locale_t locale
;
1905 ret
= (data
->have_locale
? MSVCRT__ENABLE_PER_THREAD_LOCALE
: MSVCRT__DISABLE_PER_THREAD_LOCALE
);
1907 if(type
== MSVCRT__ENABLE_PER_THREAD_LOCALE
) {
1908 if(!data
->have_locale
) {
1909 /* Copy current global locale */
1910 locale
= MSVCRT__create_locale(MSVCRT_LC_ALL
, MSVCRT_setlocale(MSVCRT_LC_ALL
, NULL
));
1914 data
->locinfo
= locale
->locinfo
;
1915 data
->mbcinfo
= locale
->mbcinfo
;
1916 data
->have_locale
= TRUE
;
1917 MSVCRT_free(locale
);
1923 if(type
== MSVCRT__DISABLE_PER_THREAD_LOCALE
) {
1924 if(data
->have_locale
) {
1925 free_locinfo(data
->locinfo
);
1926 free_mbcinfo(data
->mbcinfo
);
1927 data
->locinfo
= MSVCRT_locale
->locinfo
;
1928 data
->mbcinfo
= MSVCRT_locale
->mbcinfo
;
1929 data
->have_locale
= FALSE
;
1941 BOOL
msvcrt_init_locale(void)
1946 MSVCRT_locale
= MSVCRT__create_locale(0, "C");
1951 MSVCRT___lc_codepage
= MSVCRT_locale
->locinfo
->lc_codepage
;
1952 MSVCRT___lc_collate_cp
= MSVCRT_locale
->locinfo
->lc_collate_cp
;
1953 MSVCRT___mb_cur_max
= MSVCRT_locale
->locinfo
->mb_cur_max
;
1954 MSVCRT__pctype
= MSVCRT_locale
->locinfo
->pctype
;
1955 for(i
=MSVCRT_LC_MIN
; i
<=MSVCRT_LC_MAX
; i
++)
1956 MSVCRT___lc_handle
[i
] = MSVCRT_locale
->locinfo
->lc_handle
[i
];
1957 _setmbcp(_MB_CP_ANSI
);