2 * msvcrt.dll locale functions
4 * Copyright 2000 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
42 #define MAX_ELEM_LEN 64 /* Max length of country/language/CP string */
43 #define MAX_LOCALE_LENGTH 256
44 MSVCRT__locale_t MSVCRT_locale
= NULL
;
45 unsigned short *MSVCRT__pctype
= NULL
;
46 unsigned int MSVCRT___lc_codepage
= 0;
47 int MSVCRT___lc_collate_cp
= 0;
48 LCID MSVCRT___lc_handle
[MSVCRT_LC_MAX
- MSVCRT_LC_MIN
+ 1] = { 0 };
49 int MSVCRT___mb_cur_max
= 1;
50 static unsigned char charmax
= CHAR_MAX
;
53 #define LOCK_LOCALE _mlock(_SETLOCALE_LOCK);
54 #define UNLOCK_LOCALE _munlock(_SETLOCALE_LOCK);
56 #define MSVCRT_LEADBYTE 0x8000
57 #define MSVCRT_C1_DEFINED 0x200
59 /* Friendly country strings & language names abbreviations. */
60 static const char * const _country_synonyms
[] =
63 "american english", "enu",
64 "american-english", "enu",
65 "english-american", "enu",
73 "french-belgian", "frb",
76 "french-canadian", "frc",
78 "chinese-simplified", "chs",
79 "chinese-traditional", "cht",
80 "dutch-belgian", "nlb",
84 "french-swiss", "frs",
86 "german-swiss", "des",
87 "italian-swiss", "its",
88 "german-austrian", "dea",
90 "portuguese-brazil", "ptb",
91 "spanish-mexican", "esm",
92 "norwegian-bokmal", "nor",
93 "norwegian-nynorsk", "non",
94 "spanish-modern", "esn"
97 /* INTERNAL: Map a synonym to an ISO code */
98 static void remap_synonym(char *name
)
101 for (i
= 0; i
< sizeof(_country_synonyms
)/sizeof(char*); i
+= 2 )
103 if (!strcasecmp(_country_synonyms
[i
],name
))
105 TRACE(":Mapping synonym %s to %s\n",name
,_country_synonyms
[i
+1]);
106 strcpy(name
, _country_synonyms
[i
+1]);
112 /* Note: Flags are weighted in order of matching importance */
113 #define FOUND_LANGUAGE 0x4
114 #define FOUND_COUNTRY 0x2
115 #define FOUND_CODEPAGE 0x1
118 char search_language
[MAX_ELEM_LEN
];
119 char search_country
[MAX_ELEM_LEN
];
120 char search_codepage
[MAX_ELEM_LEN
];
121 char found_codepage
[MAX_ELEM_LEN
];
122 unsigned int match_flags
;
123 LANGID found_lang_id
;
126 #define CONTINUE_LOOKING TRUE
127 #define STOP_LOOKING FALSE
129 /* INTERNAL: Get and compare locale info with a given string */
130 static int compare_info(LCID lcid
, DWORD flags
, char* buff
, const char* cmp
, BOOL exact
)
138 GetLocaleInfoA(lcid
, flags
|LOCALE_NOUSEROVERRIDE
, buff
, MAX_ELEM_LEN
);
142 /* Partial matches are only allowed on language/country names */
145 return !strcasecmp(cmp
, buff
);
147 return !strncasecmp(cmp
, buff
, len
);
151 find_best_locale_proc(HMODULE hModule
, LPCSTR type
, LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
153 locale_search_t
*res
= (locale_search_t
*)lParam
;
154 const LCID lcid
= MAKELCID(LangID
, SORT_DEFAULT
);
155 char buff
[MAX_ELEM_LEN
];
156 unsigned int flags
= 0;
158 if(PRIMARYLANGID(LangID
) == LANG_NEUTRAL
)
159 return CONTINUE_LOOKING
;
162 if (compare_info(lcid
,LOCALE_SISO639LANGNAME
,buff
,res
->search_language
, TRUE
) ||
163 compare_info(lcid
,LOCALE_SABBREVLANGNAME
,buff
,res
->search_language
, TRUE
) ||
164 compare_info(lcid
,LOCALE_SENGLANGUAGE
,buff
,res
->search_language
, FALSE
))
166 TRACE(":Found language: %s->%s\n", res
->search_language
, buff
);
167 flags
|= FOUND_LANGUAGE
;
169 else if (res
->match_flags
& FOUND_LANGUAGE
)
171 return CONTINUE_LOOKING
;
175 if (compare_info(lcid
,LOCALE_SISO3166CTRYNAME
,buff
,res
->search_country
, TRUE
) ||
176 compare_info(lcid
,LOCALE_SABBREVCTRYNAME
,buff
,res
->search_country
, TRUE
) ||
177 compare_info(lcid
,LOCALE_SENGCOUNTRY
,buff
,res
->search_country
, FALSE
))
179 TRACE("Found country:%s->%s\n", res
->search_country
, buff
);
180 flags
|= FOUND_COUNTRY
;
182 else if (!flags
&& (res
->match_flags
& FOUND_COUNTRY
))
184 return CONTINUE_LOOKING
;
188 if (compare_info(lcid
,LOCALE_IDEFAULTCODEPAGE
,buff
,res
->search_codepage
, TRUE
) ||
189 (compare_info(lcid
,LOCALE_IDEFAULTANSICODEPAGE
,buff
,res
->search_codepage
, TRUE
)))
191 TRACE("Found codepage:%s->%s\n", res
->search_codepage
, buff
);
192 flags
|= FOUND_CODEPAGE
;
193 memcpy(res
->found_codepage
,res
->search_codepage
,MAX_ELEM_LEN
);
195 else if (!flags
&& (res
->match_flags
& FOUND_CODEPAGE
))
197 return CONTINUE_LOOKING
;
200 if (flags
> res
->match_flags
)
202 /* Found a better match than previously */
203 res
->match_flags
= flags
;
204 res
->found_lang_id
= LangID
;
206 if ((flags
& (FOUND_LANGUAGE
| FOUND_COUNTRY
| FOUND_CODEPAGE
)) ==
207 (FOUND_LANGUAGE
| FOUND_COUNTRY
| FOUND_CODEPAGE
))
209 TRACE(":found exact locale match\n");
212 return CONTINUE_LOOKING
;
215 extern int atoi(const char *);
217 /* Internal: Find the LCID for a locale specification */
218 LCID
MSVCRT_locale_to_LCID(const char *locale
, unsigned short *codepage
)
220 thread_data_t
*data
= msvcrt_get_thread_data();
222 locale_search_t search
;
223 const char *cp
, *region
;
225 if (!strcmp(locale
, data
->cached_locale
)) {
227 *codepage
= data
->cached_cp
;
228 return data
->cached_lcid
;
231 memset(&search
, 0, sizeof(locale_search_t
));
233 cp
= strchr(locale
, '.');
234 region
= strchr(locale
, '_');
236 lstrcpynA(search
.search_language
, locale
, MAX_ELEM_LEN
);
238 lstrcpynA(search
.search_country
, region
+1, MAX_ELEM_LEN
);
239 if(region
-locale
< MAX_ELEM_LEN
)
240 search
.search_language
[region
-locale
] = '\0';
242 search
.search_country
[0] = '\0';
245 lstrcpynA(search
.search_codepage
, cp
+1, MAX_ELEM_LEN
);
246 if(region
&& cp
-region
-1<MAX_ELEM_LEN
)
247 search
.search_country
[cp
-region
-1] = '\0';
248 if(cp
-locale
< MAX_ELEM_LEN
)
249 search
.search_language
[cp
-locale
] = '\0';
251 search
.search_codepage
[0] = '\0';
253 if(!search
.search_country
[0] && !search
.search_codepage
[0])
254 remap_synonym(search
.search_language
);
256 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), (LPSTR
)RT_STRING
,
257 (LPCSTR
)LOCALE_ILANGUAGE
,find_best_locale_proc
,
260 if (!search
.match_flags
)
263 /* If we were given something that didn't match, fail */
264 if (search
.search_country
[0] && !(search
.match_flags
& FOUND_COUNTRY
))
267 lcid
= MAKELCID(search
.found_lang_id
, SORT_DEFAULT
);
269 /* Populate partial locale, translating LCID to locale string elements */
270 if (!(search
.match_flags
& FOUND_CODEPAGE
)) {
271 /* Even if a codepage is not enumerated for a locale
272 * it can be set if valid */
273 if (search
.search_codepage
[0]) {
274 if (IsValidCodePage(atoi(search
.search_codepage
)))
275 memcpy(search
.found_codepage
,search
.search_codepage
,MAX_ELEM_LEN
);
277 /* Special codepage values: OEM & ANSI */
278 if (!strcasecmp(search
.search_codepage
,"OCP")) {
279 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTCODEPAGE
,
280 search
.found_codepage
, MAX_ELEM_LEN
);
281 } else if (!strcasecmp(search
.search_codepage
,"ACP")) {
282 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
,
283 search
.found_codepage
, MAX_ELEM_LEN
);
287 if (!atoi(search
.found_codepage
))
291 /* Prefer ANSI codepages if present */
292 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
,
293 search
.found_codepage
, MAX_ELEM_LEN
);
294 if (!search
.found_codepage
[0] || !atoi(search
.found_codepage
))
295 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTCODEPAGE
,
296 search
.found_codepage
, MAX_ELEM_LEN
);
300 *codepage
= atoi(search
.found_codepage
);
302 if (strlen(locale
) < sizeof(data
->cached_locale
)) {
303 strcpy(data
->cached_locale
, locale
);
304 data
->cached_lcid
= lcid
;
305 data
->cached_cp
= codepage
? *codepage
: atoi(search
.found_codepage
);
311 /* INTERNAL: Set lc_handle, lc_id and lc_category in threadlocinfo struct */
312 static BOOL
update_threadlocinfo_category(LCID lcid
, unsigned short cp
,
313 MSVCRT__locale_t loc
, int category
)
318 if(GetLocaleInfoA(lcid
, LOCALE_ILANGUAGE
|LOCALE_NOUSEROVERRIDE
, buf
, 256)) {
321 loc
->locinfo
->lc_id
[category
].wLanguage
= 0;
323 loc
->locinfo
->lc_id
[category
].wLanguage
*= 16;
326 loc
->locinfo
->lc_id
[category
].wLanguage
+= *p
-'0';
328 loc
->locinfo
->lc_id
[category
].wLanguage
+= *p
-'a'+10;
333 loc
->locinfo
->lc_id
[category
].wCountry
=
334 loc
->locinfo
->lc_id
[category
].wLanguage
;
337 loc
->locinfo
->lc_id
[category
].wCodePage
= cp
;
339 loc
->locinfo
->lc_handle
[category
] = lcid
;
342 len
+= GetLocaleInfoA(lcid
, LOCALE_SENGLANGUAGE
343 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
345 len
+= GetLocaleInfoA(lcid
, LOCALE_SENGCOUNTRY
346 |LOCALE_NOUSEROVERRIDE
, &buf
[len
], 256-len
);
348 sprintf(buf
+len
, "%d", cp
);
349 len
+= strlen(buf
+len
)+1;
351 loc
->locinfo
->lc_category
[category
].locale
= MSVCRT_malloc(len
);
352 loc
->locinfo
->lc_category
[category
].refcount
= MSVCRT_malloc(sizeof(int));
353 if(!loc
->locinfo
->lc_category
[category
].locale
354 || !loc
->locinfo
->lc_category
[category
].refcount
) {
355 MSVCRT_free(loc
->locinfo
->lc_category
[category
].locale
);
356 MSVCRT_free(loc
->locinfo
->lc_category
[category
].refcount
);
357 loc
->locinfo
->lc_category
[category
].locale
= NULL
;
358 loc
->locinfo
->lc_category
[category
].refcount
= NULL
;
361 memcpy(loc
->locinfo
->lc_category
[category
].locale
, buf
, len
);
362 *loc
->locinfo
->lc_category
[category
].refcount
= 1;
367 /* INTERNAL: swap pointers values */
368 static inline void swap_pointers(void **p1
, void **p2
) {
376 /* INTERNAL: returns pthreadlocinfo struct */
377 MSVCRT_pthreadlocinfo
get_locinfo(void) {
378 thread_data_t
*data
= msvcrt_get_thread_data();
380 if(!data
|| !data
->have_locale
)
381 return MSVCRT_locale
->locinfo
;
383 return data
->locinfo
;
386 /* INTERNAL: returns pthreadlocinfo struct */
387 MSVCRT_pthreadmbcinfo
get_mbcinfo(void) {
388 thread_data_t
*data
= msvcrt_get_thread_data();
390 if(!data
|| !data
->have_locale
)
391 return MSVCRT_locale
->mbcinfo
;
393 return data
->mbcinfo
;
396 /* INTERNAL: constructs string returned by setlocale */
397 static inline char* construct_lc_all(MSVCRT_pthreadlocinfo locinfo
) {
398 static char current_lc_all
[MAX_LOCALE_LENGTH
];
402 for(i
=MSVCRT_LC_MIN
+1; i
<MSVCRT_LC_MAX
; i
++) {
403 if(strcmp(locinfo
->lc_category
[i
].locale
,
404 locinfo
->lc_category
[i
+1].locale
))
409 return locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
;
411 sprintf(current_lc_all
,
412 "LC_COLLATE=%s;LC_CTYPE=%s;LC_MONETARY=%s;LC_NUMERIC=%s;LC_TIME=%s",
413 locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
,
414 locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
,
415 locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
,
416 locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
,
417 locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
);
419 return current_lc_all
;
423 /*********************************************************************
424 * _Getdays (MSVCRT.@)
426 char* CDECL
_Getdays(void)
428 MSVCRT___lc_time_data
*cur
= get_locinfo()->lc_time_curr
;
434 size
= cur
->str
.names
.short_mon
[0]-cur
->str
.names
.short_wday
[0];
435 out
= MSVCRT_malloc(size
+1);
442 len
= strlen(cur
->str
.names
.short_wday
[i
]);
443 memcpy(&out
[size
], cur
->str
.names
.short_wday
[i
], len
);
447 len
= strlen(cur
->str
.names
.wday
[i
]);
448 memcpy(&out
[size
], cur
->str
.names
.wday
[i
], len
);
456 /*********************************************************************
457 * _W_Getdays (MSVCRT.@)
459 MSVCRT_wchar_t
* CDECL
_W_Getdays(void)
461 MSVCRT___lc_time_data
*cur
= get_locinfo()->lc_time_curr
;
467 size
= cur
->wstr
.names
.short_mon
[0]-cur
->wstr
.names
.short_wday
[0];
468 out
= MSVCRT_malloc((size
+1)*sizeof(*out
));
475 len
= strlenW(cur
->wstr
.names
.short_wday
[i
]);
476 memcpy(&out
[size
], cur
->wstr
.names
.short_wday
[i
], len
*sizeof(*out
));
480 len
= strlenW(cur
->wstr
.names
.wday
[i
]);
481 memcpy(&out
[size
], cur
->wstr
.names
.wday
[i
], len
*sizeof(*out
));
489 /*********************************************************************
490 * _Getmonths (MSVCRT.@)
492 char* CDECL
_Getmonths(void)
494 MSVCRT___lc_time_data
*cur
= get_locinfo()->lc_time_curr
;
500 size
= cur
->str
.names
.am
-cur
->str
.names
.short_mon
[0];
501 out
= MSVCRT_malloc(size
+1);
506 for(i
=0; i
<12; i
++) {
508 len
= strlen(cur
->str
.names
.short_mon
[i
]);
509 memcpy(&out
[size
], cur
->str
.names
.short_mon
[i
], len
);
513 len
= strlen(cur
->str
.names
.mon
[i
]);
514 memcpy(&out
[size
], cur
->str
.names
.mon
[i
], len
);
522 /*********************************************************************
523 * _W_Getmonths (MSVCRT.@)
525 MSVCRT_wchar_t
* CDECL
_W_Getmonths(void)
527 MSVCRT___lc_time_data
*cur
= get_locinfo()->lc_time_curr
;
533 size
= cur
->wstr
.names
.am
-cur
->wstr
.names
.short_mon
[0];
534 out
= MSVCRT_malloc((size
+1)*sizeof(*out
));
539 for(i
=0; i
<12; i
++) {
541 len
= strlenW(cur
->wstr
.names
.short_mon
[i
]);
542 memcpy(&out
[size
], cur
->wstr
.names
.short_mon
[i
], len
*sizeof(*out
));
546 len
= strlenW(cur
->wstr
.names
.mon
[i
]);
547 memcpy(&out
[size
], cur
->wstr
.names
.mon
[i
], len
*sizeof(*out
));
555 /*********************************************************************
556 * _Gettnames (MSVCRT.@)
558 void* CDECL
_Gettnames(void)
560 MSVCRT___lc_time_data
*ret
, *cur
= get_locinfo()->lc_time_curr
;
561 unsigned int i
, size
= sizeof(MSVCRT___lc_time_data
);
565 for(i
=0; i
<sizeof(cur
->str
.str
)/sizeof(cur
->str
.str
[0]); i
++)
566 size
+= strlen(cur
->str
.str
[i
])+1;
568 ret
= MSVCRT_malloc(size
);
571 memcpy(ret
, cur
, size
);
574 for(i
=0; i
<sizeof(cur
->str
.str
)/sizeof(cur
->str
.str
[0]); i
++) {
575 ret
->str
.str
[i
] = &ret
->data
[size
];
576 size
+= strlen(&ret
->data
[size
])+1;
582 /*********************************************************************
583 * __crtLCMapStringA (MSVCRT.@)
585 int CDECL
__crtLCMapStringA(
586 LCID lcid
, DWORD mapflags
, const char* src
, int srclen
, char* dst
,
587 int dstlen
, unsigned int codepage
, int xflag
589 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
590 lcid
,mapflags
,src
,srclen
,dst
,dstlen
,codepage
,xflag
);
591 /* FIXME: A bit incorrect. But msvcrt itself just converts its
592 * arguments to wide strings and then calls LCMapStringW
594 return LCMapStringA(lcid
,mapflags
,src
,srclen
,dst
,dstlen
);
597 /*********************************************************************
598 * __crtLCMapStringW (MSVCRT.@)
600 int CDECL
__crtLCMapStringW(LCID lcid
, DWORD mapflags
, const MSVCRT_wchar_t
*src
,
601 int srclen
, MSVCRT_wchar_t
*dst
, int dstlen
, unsigned int codepage
, int xflag
)
603 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
604 lcid
, mapflags
, debugstr_w(src
), srclen
, dst
, dstlen
, codepage
, xflag
);
606 return LCMapStringW(lcid
, mapflags
, src
, srclen
, dst
, dstlen
);
609 /*********************************************************************
610 * __crtCompareStringA (MSVCRT.@)
612 int CDECL
__crtCompareStringA( LCID lcid
, DWORD flags
, const char *src1
, int len1
,
613 const char *src2
, int len2
)
615 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
616 lcid
, flags
, debugstr_a(src1
), len1
, debugstr_a(src2
), len2
);
617 /* FIXME: probably not entirely right */
618 return CompareStringA( lcid
, flags
, src1
, len1
, src2
, len2
);
621 /*********************************************************************
622 * __crtCompareStringW (MSVCRT.@)
624 int CDECL
__crtCompareStringW( LCID lcid
, DWORD flags
, const MSVCRT_wchar_t
*src1
, int len1
,
625 const MSVCRT_wchar_t
*src2
, int len2
)
627 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
628 lcid
, flags
, debugstr_w(src1
), len1
, debugstr_w(src2
), len2
);
629 /* FIXME: probably not entirely right */
630 return CompareStringW( lcid
, flags
, src1
, len1
, src2
, len2
);
633 /*********************************************************************
634 * __crtGetLocaleInfoW (MSVCRT.@)
636 int CDECL
__crtGetLocaleInfoW( LCID lcid
, LCTYPE type
, MSVCRT_wchar_t
*buffer
, int len
)
638 FIXME("(lcid %x, type %x, %p(%d), partial stub\n", lcid
, type
, buffer
, len
);
639 /* FIXME: probably not entirely right */
640 return GetLocaleInfoW( lcid
, type
, buffer
, len
);
643 /*********************************************************************
644 * __crtGetLocaleInfoEx (MSVC110.@)
646 int CDECL
__crtGetLocaleInfoEx( const WCHAR
*locale
, LCTYPE type
, MSVCRT_wchar_t
*buffer
, int len
)
648 TRACE("(%s, %x, %p, %d)\n", debugstr_w(locale
), type
, buffer
, len
);
649 return GetLocaleInfoEx(locale
, type
, buffer
, len
);
652 /*********************************************************************
655 MSVCRT_wint_t CDECL
MSVCRT_btowc(int c
)
657 unsigned char letter
= c
;
660 if(!MultiByteToWideChar(get_locinfo()->lc_handle
[MSVCRT_LC_CTYPE
],
661 0, (LPCSTR
)&letter
, 1, &ret
, 1))
667 /*********************************************************************
668 * __crtGetStringTypeW(MSVCRT.@)
670 * This function was accepting different number of arguments in older
671 * versions of msvcrt.
673 BOOL CDECL
__crtGetStringTypeW(DWORD unk
, DWORD type
,
674 MSVCRT_wchar_t
*buffer
, int len
, WORD
*out
)
676 FIXME("(unk %x, type %x, wstr %p(%d), %p) partial stub\n",
677 unk
, type
, buffer
, len
, out
);
679 return GetStringTypeW(type
, buffer
, len
, out
);
682 /*********************************************************************
683 * localeconv (MSVCRT.@)
685 struct MSVCRT_lconv
* CDECL
MSVCRT_localeconv(void)
687 return get_locinfo()->lconv
;
690 /*********************************************************************
691 * __lconv_init (MSVCRT.@)
693 int CDECL
__lconv_init(void)
695 /* this is used to make chars unsigned */
700 /*********************************************************************
701 * ___lc_handle_func (MSVCRT.@)
703 LCID
* CDECL
___lc_handle_func(void)
705 return get_locinfo()->lc_handle
;
708 /*********************************************************************
709 * ___lc_locale_name_func (MSVCR110.@)
711 #if _MSVCR_VER >= 110
712 MSVCRT_wchar_t
** CDECL
___lc_locale_name_func(void)
714 return get_locinfo()->lc_name
;
718 /*********************************************************************
719 * ___lc_codepage_func (MSVCRT.@)
721 unsigned int CDECL
___lc_codepage_func(void)
723 return get_locinfo()->lc_codepage
;
726 /*********************************************************************
727 * ___lc_collate_cp_func (MSVCRT.@)
729 int CDECL
___lc_collate_cp_func(void)
731 return get_locinfo()->lc_collate_cp
;
734 /* INTERNAL: frees MSVCRT_pthreadlocinfo struct */
735 void free_locinfo(MSVCRT_pthreadlocinfo locinfo
)
742 if(InterlockedDecrement(&locinfo
->refcount
))
745 for(i
=MSVCRT_LC_MIN
+1; i
<=MSVCRT_LC_MAX
; i
++) {
746 MSVCRT_free(locinfo
->lc_category
[i
].locale
);
747 MSVCRT_free(locinfo
->lc_category
[i
].refcount
);
748 #if _MSVCR_VER >= 110
749 MSVCRT_free(locinfo
->lc_name
[i
]);
754 MSVCRT_free(locinfo
->lconv
->decimal_point
);
755 MSVCRT_free(locinfo
->lconv
->thousands_sep
);
756 MSVCRT_free(locinfo
->lconv
->grouping
);
757 MSVCRT_free(locinfo
->lconv
->int_curr_symbol
);
758 MSVCRT_free(locinfo
->lconv
->currency_symbol
);
759 MSVCRT_free(locinfo
->lconv
->mon_decimal_point
);
760 MSVCRT_free(locinfo
->lconv
->mon_thousands_sep
);
761 MSVCRT_free(locinfo
->lconv
->mon_grouping
);
762 MSVCRT_free(locinfo
->lconv
->positive_sign
);
763 MSVCRT_free(locinfo
->lconv
->negative_sign
);
764 #if _MSVCR_VER >= 120
765 MSVCRT_free(locinfo
->lconv
->_W_decimal_point
);
766 MSVCRT_free(locinfo
->lconv
->_W_thousands_sep
);
767 MSVCRT_free(locinfo
->lconv
->_W_int_curr_symbol
);
768 MSVCRT_free(locinfo
->lconv
->_W_currency_symbol
);
769 MSVCRT_free(locinfo
->lconv
->_W_mon_decimal_point
);
770 MSVCRT_free(locinfo
->lconv
->_W_mon_thousands_sep
);
771 MSVCRT_free(locinfo
->lconv
->_W_positive_sign
);
772 MSVCRT_free(locinfo
->lconv
->_W_negative_sign
);
775 MSVCRT_free(locinfo
->lconv_intl_refcount
);
776 MSVCRT_free(locinfo
->lconv_num_refcount
);
777 MSVCRT_free(locinfo
->lconv_mon_refcount
);
778 MSVCRT_free(locinfo
->lconv
);
780 MSVCRT_free(locinfo
->ctype1_refcount
);
781 MSVCRT_free(locinfo
->ctype1
);
783 MSVCRT_free(locinfo
->pclmap
);
784 MSVCRT_free(locinfo
->pcumap
);
786 MSVCRT_free(locinfo
->lc_time_curr
);
788 MSVCRT_free(locinfo
);
791 /* INTERNAL: frees MSVCRT_pthreadmbcinfo struct */
792 void free_mbcinfo(MSVCRT_pthreadmbcinfo mbcinfo
)
797 if(InterlockedDecrement(&mbcinfo
->refcount
))
800 MSVCRT_free(mbcinfo
);
803 /*********************************************************************
804 * _get_current_locale (MSVCRT.@)
806 MSVCRT__locale_t CDECL
MSVCRT__get_current_locale(void)
808 MSVCRT__locale_t loc
= MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct
));
812 loc
->locinfo
= get_locinfo();
813 loc
->mbcinfo
= get_mbcinfo();
814 InterlockedIncrement(&loc
->locinfo
->refcount
);
815 InterlockedIncrement(&loc
->mbcinfo
->refcount
);
819 /*********************************************************************
820 * _free_locale (MSVCRT.@)
822 void CDECL
MSVCRT__free_locale(MSVCRT__locale_t locale
)
827 free_locinfo(locale
->locinfo
);
828 free_mbcinfo(locale
->mbcinfo
);
832 #if _MSVCR_VER >= 110
833 static inline BOOL
set_lc_locale_name(MSVCRT__locale_t loc
, int cat
)
835 LCID lcid
= loc
->locinfo
->lc_handle
[cat
];
839 len
= GetLocaleInfoW(lcid
, LOCALE_SISO639LANGNAME
840 |LOCALE_NOUSEROVERRIDE
, buf
, 100);
841 if(!len
) return FALSE
;
843 if(LocaleNameToLCID(buf
, 0) != lcid
)
844 len
= LCIDToLocaleName(lcid
, buf
, 100, 0);
846 if(!len
|| !(loc
->locinfo
->lc_name
[cat
] = MSVCRT_malloc(len
*sizeof(MSVCRT_wchar_t
))))
849 memcpy(loc
->locinfo
->lc_name
[cat
], buf
, len
*sizeof(MSVCRT_wchar_t
));
853 static inline BOOL
set_lc_locale_name(MSVCRT__locale_t loc
, int cat
)
859 /*********************************************************************
860 * _create_locale (MSVCRT.@)
862 MSVCRT__locale_t CDECL
MSVCRT__create_locale(int category
, const char *locale
)
864 static const DWORD time_data
[] = {
865 LOCALE_SABBREVDAYNAME7
, LOCALE_SABBREVDAYNAME1
, LOCALE_SABBREVDAYNAME2
,
866 LOCALE_SABBREVDAYNAME3
, LOCALE_SABBREVDAYNAME4
, LOCALE_SABBREVDAYNAME5
,
867 LOCALE_SABBREVDAYNAME6
,
868 LOCALE_SDAYNAME7
, LOCALE_SDAYNAME1
, LOCALE_SDAYNAME2
, LOCALE_SDAYNAME3
,
869 LOCALE_SDAYNAME4
, LOCALE_SDAYNAME5
, LOCALE_SDAYNAME6
,
870 LOCALE_SABBREVMONTHNAME1
, LOCALE_SABBREVMONTHNAME2
, LOCALE_SABBREVMONTHNAME3
,
871 LOCALE_SABBREVMONTHNAME4
, LOCALE_SABBREVMONTHNAME5
, LOCALE_SABBREVMONTHNAME6
,
872 LOCALE_SABBREVMONTHNAME7
, LOCALE_SABBREVMONTHNAME8
, LOCALE_SABBREVMONTHNAME9
,
873 LOCALE_SABBREVMONTHNAME10
, LOCALE_SABBREVMONTHNAME11
, LOCALE_SABBREVMONTHNAME12
,
874 LOCALE_SMONTHNAME1
, LOCALE_SMONTHNAME2
, LOCALE_SMONTHNAME3
, LOCALE_SMONTHNAME4
,
875 LOCALE_SMONTHNAME5
, LOCALE_SMONTHNAME6
, LOCALE_SMONTHNAME7
, LOCALE_SMONTHNAME8
,
876 LOCALE_SMONTHNAME9
, LOCALE_SMONTHNAME10
, LOCALE_SMONTHNAME11
, LOCALE_SMONTHNAME12
,
877 LOCALE_S1159
, LOCALE_S2359
,
878 LOCALE_SSHORTDATE
, LOCALE_SLONGDATE
,
881 static const char collate
[] = "COLLATE=";
882 static const char ctype
[] = "CTYPE=";
883 static const char monetary
[] = "MONETARY=";
884 static const char numeric
[] = "NUMERIC=";
885 static const char time
[] = "TIME=";
886 static const char cloc_short_date
[] = "MM/dd/yy";
887 static const MSVCRT_wchar_t cloc_short_dateW
[] = {'M','M','/','d','d','/','y','y',0};
888 static const char cloc_long_date
[] = "dddd, MMMM dd, yyyy";
889 static const MSVCRT_wchar_t cloc_long_dateW
[] = {'d','d','d','d',',',' ','M','M','M','M',' ','d','d',',',' ','y','y','y','y',0};
890 static const char cloc_time
[] = "HH:mm:ss";
891 static const MSVCRT_wchar_t cloc_timeW
[] = {'H','H',':','m','m',':','s','s',0};
893 MSVCRT__locale_t loc
;
894 LCID lcid
[6] = { 0 }, lcid_tmp
;
895 unsigned short cp
[6] = { 0 };
897 #if _MSVCR_VER >= 120
898 MSVCRT_wchar_t wbuf
[256];
902 TRACE("(%d %s)\n", category
, locale
);
904 if(category
<MSVCRT_LC_MIN
|| category
>MSVCRT_LC_MAX
|| !locale
)
907 if(locale
[0]=='C' && !locale
[1]) {
910 } else if(!locale
[0]) {
911 lcid
[0] = GetSystemDefaultLCID();
912 GetLocaleInfoA(lcid
[0], LOCALE_IDEFAULTANSICODEPAGE
913 |LOCALE_NOUSEROVERRIDE
, buf
, sizeof(buf
));
920 } else if (locale
[0] == 'L' && locale
[1] == 'C' && locale
[2] == '_') {
924 locale
+= 3; /* LC_ */
925 if(!memcmp(locale
, collate
, sizeof(collate
)-1)) {
926 i
= MSVCRT_LC_COLLATE
;
927 locale
+= sizeof(collate
)-1;
928 } else if(!memcmp(locale
, ctype
, sizeof(ctype
)-1)) {
930 locale
+= sizeof(ctype
)-1;
931 } else if(!memcmp(locale
, monetary
, sizeof(monetary
)-1)) {
932 i
= MSVCRT_LC_MONETARY
;
933 locale
+= sizeof(monetary
)-1;
934 } else if(!memcmp(locale
, numeric
, sizeof(numeric
)-1)) {
935 i
= MSVCRT_LC_NUMERIC
;
936 locale
+= sizeof(numeric
)-1;
937 } else if(!memcmp(locale
, time
, sizeof(time
)-1)) {
939 locale
+= sizeof(time
)-1;
943 p
= strchr(locale
, ';');
944 if(locale
[0]=='C' && (locale
[1]==';' || locale
[1]=='\0')) {
948 memcpy(buf
, locale
, p
-locale
);
949 buf
[p
-locale
] = '\0';
950 lcid
[i
] = MSVCRT_locale_to_LCID(buf
, &cp
[i
]);
952 lcid
[i
] = MSVCRT_locale_to_LCID(locale
, &cp
[i
]);
957 if(!p
|| *(p
+1)!='L' || *(p
+2)!='C' || *(p
+3)!='_')
963 lcid
[0] = MSVCRT_locale_to_LCID(locale
, &cp
[0]);
973 loc
= MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct
));
977 loc
->locinfo
= MSVCRT_malloc(sizeof(MSVCRT_threadlocinfo
));
983 loc
->mbcinfo
= MSVCRT_malloc(sizeof(MSVCRT_threadmbcinfo
));
985 MSVCRT_free(loc
->locinfo
);
990 memset(loc
->locinfo
, 0, sizeof(MSVCRT_threadlocinfo
));
991 loc
->locinfo
->refcount
= 1;
992 loc
->mbcinfo
->refcount
= 1;
994 loc
->locinfo
->lconv
= MSVCRT_malloc(sizeof(struct MSVCRT_lconv
));
995 if(!loc
->locinfo
->lconv
) {
996 MSVCRT__free_locale(loc
);
999 memset(loc
->locinfo
->lconv
, 0, sizeof(struct MSVCRT_lconv
));
1001 loc
->locinfo
->pclmap
= MSVCRT_malloc(sizeof(char[256]));
1002 loc
->locinfo
->pcumap
= MSVCRT_malloc(sizeof(char[256]));
1003 if(!loc
->locinfo
->pclmap
|| !loc
->locinfo
->pcumap
) {
1004 MSVCRT__free_locale(loc
);
1008 if(lcid
[MSVCRT_LC_COLLATE
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_COLLATE
)) {
1009 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_COLLATE
], cp
[MSVCRT_LC_COLLATE
], loc
, MSVCRT_LC_COLLATE
)) {
1010 MSVCRT__free_locale(loc
);
1014 loc
->locinfo
->lc_collate_cp
= loc
->locinfo
->lc_id
[MSVCRT_LC_COLLATE
].wCodePage
;
1016 if(!set_lc_locale_name(loc
, MSVCRT_LC_COLLATE
)) {
1017 MSVCRT__free_locale(loc
);
1021 loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
= MSVCRT__strdup("C");
1023 if(lcid
[MSVCRT_LC_CTYPE
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_CTYPE
)) {
1027 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_CTYPE
], cp
[MSVCRT_LC_CTYPE
], loc
, MSVCRT_LC_CTYPE
)) {
1028 MSVCRT__free_locale(loc
);
1032 loc
->locinfo
->lc_codepage
= loc
->locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
;
1033 loc
->locinfo
->lc_clike
= 1;
1034 if(!GetCPInfo(loc
->locinfo
->lc_codepage
, &cp_info
)) {
1035 MSVCRT__free_locale(loc
);
1038 loc
->locinfo
->mb_cur_max
= cp_info
.MaxCharSize
;
1040 loc
->locinfo
->ctype1_refcount
= MSVCRT_malloc(sizeof(int));
1041 loc
->locinfo
->ctype1
= MSVCRT_malloc(sizeof(short[257]));
1042 if(!loc
->locinfo
->ctype1_refcount
|| !loc
->locinfo
->ctype1
) {
1043 MSVCRT__free_locale(loc
);
1047 *loc
->locinfo
->ctype1_refcount
= 1;
1048 loc
->locinfo
->ctype1
[0] = 0;
1049 loc
->locinfo
->pctype
= loc
->locinfo
->ctype1
+1;
1051 buf
[1] = buf
[2] = '\0';
1052 for(i
=1; i
<257; i
++) {
1055 /* builtin GetStringTypeA doesn't set output to 0 on invalid input */
1056 loc
->locinfo
->ctype1
[i
] = 0;
1058 GetStringTypeA(lcid
[MSVCRT_LC_CTYPE
], CT_CTYPE1
, buf
,
1059 1, loc
->locinfo
->ctype1
+i
);
1062 for(i
=0; cp_info
.LeadByte
[i
+1]!=0; i
+=2)
1063 for(j
=cp_info
.LeadByte
[i
]; j
<=cp_info
.LeadByte
[i
+1]; j
++)
1064 loc
->locinfo
->ctype1
[j
+1] |= MSVCRT__LEADBYTE
;
1066 if(!set_lc_locale_name(loc
, MSVCRT_LC_CTYPE
)) {
1067 MSVCRT__free_locale(loc
);
1071 loc
->locinfo
->lc_clike
= 1;
1072 loc
->locinfo
->mb_cur_max
= 1;
1073 loc
->locinfo
->pctype
= MSVCRT__ctype
+1;
1074 loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
= MSVCRT__strdup("C");
1077 for(i
=0; i
<256; i
++) {
1078 if(loc
->locinfo
->pctype
[i
] & MSVCRT__LEADBYTE
)
1085 if(lcid
[MSVCRT_LC_CTYPE
]) {
1086 LCMapStringA(lcid
[MSVCRT_LC_CTYPE
], LCMAP_LOWERCASE
, buf
, 256,
1087 (char*)loc
->locinfo
->pclmap
, 256);
1088 LCMapStringA(lcid
[MSVCRT_LC_CTYPE
], LCMAP_UPPERCASE
, buf
, 256,
1089 (char*)loc
->locinfo
->pcumap
, 256);
1091 for(i
=0; i
<256; i
++) {
1092 loc
->locinfo
->pclmap
[i
] = (i
>='A' && i
<='Z' ? i
-'A'+'a' : i
);
1093 loc
->locinfo
->pcumap
[i
] = (i
>='a' && i
<='z' ? i
-'a'+'A' : i
);
1097 _setmbcp_l(loc
->locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
, lcid
[MSVCRT_LC_CTYPE
], loc
->mbcinfo
);
1099 if(lcid
[MSVCRT_LC_MONETARY
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_MONETARY
)) {
1100 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_MONETARY
], cp
[MSVCRT_LC_MONETARY
], loc
, MSVCRT_LC_MONETARY
)) {
1101 MSVCRT__free_locale(loc
);
1105 loc
->locinfo
->lconv_intl_refcount
= MSVCRT_malloc(sizeof(int));
1106 loc
->locinfo
->lconv_mon_refcount
= MSVCRT_malloc(sizeof(int));
1107 if(!loc
->locinfo
->lconv_intl_refcount
|| !loc
->locinfo
->lconv_mon_refcount
) {
1108 MSVCRT__free_locale(loc
);
1112 *loc
->locinfo
->lconv_intl_refcount
= 1;
1113 *loc
->locinfo
->lconv_mon_refcount
= 1;
1115 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SINTLSYMBOL
1116 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1117 if(i
&& (loc
->locinfo
->lconv
->int_curr_symbol
= MSVCRT_malloc(i
)))
1118 memcpy(loc
->locinfo
->lconv
->int_curr_symbol
, buf
, i
);
1120 MSVCRT__free_locale(loc
);
1124 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SCURRENCY
1125 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1126 if(i
&& (loc
->locinfo
->lconv
->currency_symbol
= MSVCRT_malloc(i
)))
1127 memcpy(loc
->locinfo
->lconv
->currency_symbol
, buf
, i
);
1129 MSVCRT__free_locale(loc
);
1133 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONDECIMALSEP
1134 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1135 if(i
&& (loc
->locinfo
->lconv
->mon_decimal_point
= MSVCRT_malloc(i
)))
1136 memcpy(loc
->locinfo
->lconv
->mon_decimal_point
, buf
, i
);
1138 MSVCRT__free_locale(loc
);
1142 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONTHOUSANDSEP
1143 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1144 if(i
&& (loc
->locinfo
->lconv
->mon_thousands_sep
= MSVCRT_malloc(i
)))
1145 memcpy(loc
->locinfo
->lconv
->mon_thousands_sep
, buf
, i
);
1147 MSVCRT__free_locale(loc
);
1151 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONGROUPING
1152 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1154 i
= i
/2 + (buf
[i
-2]=='0'?0:1);
1155 if(i
&& (loc
->locinfo
->lconv
->mon_grouping
= MSVCRT_malloc(i
))) {
1156 for(i
=0; buf
[i
+1]==';'; i
+=2)
1157 loc
->locinfo
->lconv
->mon_grouping
[i
/2] = buf
[i
]-'0';
1158 loc
->locinfo
->lconv
->mon_grouping
[i
/2] = buf
[i
]-'0';
1160 loc
->locinfo
->lconv
->mon_grouping
[i
/2+1] = 127;
1162 MSVCRT__free_locale(loc
);
1166 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SPOSITIVESIGN
1167 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1168 if(i
&& (loc
->locinfo
->lconv
->positive_sign
= MSVCRT_malloc(i
)))
1169 memcpy(loc
->locinfo
->lconv
->positive_sign
, buf
, i
);
1171 MSVCRT__free_locale(loc
);
1175 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SNEGATIVESIGN
1176 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1177 if(i
&& (loc
->locinfo
->lconv
->negative_sign
= MSVCRT_malloc(i
)))
1178 memcpy(loc
->locinfo
->lconv
->negative_sign
, buf
, i
);
1180 MSVCRT__free_locale(loc
);
1184 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IINTLCURRDIGITS
1185 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1186 loc
->locinfo
->lconv
->int_frac_digits
= atoi(buf
);
1188 MSVCRT__free_locale(loc
);
1192 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_ICURRDIGITS
1193 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1194 loc
->locinfo
->lconv
->frac_digits
= atoi(buf
);
1196 MSVCRT__free_locale(loc
);
1200 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSYMPRECEDES
1201 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1202 loc
->locinfo
->lconv
->p_cs_precedes
= atoi(buf
);
1204 MSVCRT__free_locale(loc
);
1208 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSEPBYSPACE
1209 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1210 loc
->locinfo
->lconv
->p_sep_by_space
= atoi(buf
);
1212 MSVCRT__free_locale(loc
);
1216 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSYMPRECEDES
1217 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1218 loc
->locinfo
->lconv
->n_cs_precedes
= atoi(buf
);
1220 MSVCRT__free_locale(loc
);
1224 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSEPBYSPACE
1225 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1226 loc
->locinfo
->lconv
->n_sep_by_space
= atoi(buf
);
1228 MSVCRT__free_locale(loc
);
1232 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSIGNPOSN
1233 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1234 loc
->locinfo
->lconv
->p_sign_posn
= atoi(buf
);
1236 MSVCRT__free_locale(loc
);
1240 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSIGNPOSN
1241 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
1242 loc
->locinfo
->lconv
->n_sign_posn
= atoi(buf
);
1244 MSVCRT__free_locale(loc
);
1248 #if _MSVCR_VER >= 120
1249 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SINTLSYMBOL
1250 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1251 if(i
&& (loc
->locinfo
->lconv
->_W_int_curr_symbol
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1252 memcpy(loc
->locinfo
->lconv
->_W_int_curr_symbol
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1254 MSVCRT__free_locale(loc
);
1258 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SCURRENCY
1259 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1260 if(i
&& (loc
->locinfo
->lconv
->_W_currency_symbol
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1261 memcpy(loc
->locinfo
->lconv
->_W_currency_symbol
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1263 MSVCRT__free_locale(loc
);
1267 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONDECIMALSEP
1268 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1269 if(i
&& (loc
->locinfo
->lconv
->_W_mon_decimal_point
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1270 memcpy(loc
->locinfo
->lconv
->_W_mon_decimal_point
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1272 MSVCRT__free_locale(loc
);
1276 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONTHOUSANDSEP
1277 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1278 if(i
&& (loc
->locinfo
->lconv
->_W_mon_thousands_sep
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1279 memcpy(loc
->locinfo
->lconv
->_W_mon_thousands_sep
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1281 MSVCRT__free_locale(loc
);
1285 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SPOSITIVESIGN
1286 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1287 if(i
&& (loc
->locinfo
->lconv
->_W_positive_sign
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1288 memcpy(loc
->locinfo
->lconv
->_W_positive_sign
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1290 MSVCRT__free_locale(loc
);
1294 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SNEGATIVESIGN
1295 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1296 if(i
&& (loc
->locinfo
->lconv
->_W_negative_sign
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1297 memcpy(loc
->locinfo
->lconv
->_W_negative_sign
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1299 MSVCRT__free_locale(loc
);
1304 if(!set_lc_locale_name(loc
, MSVCRT_LC_MONETARY
)) {
1305 MSVCRT__free_locale(loc
);
1309 loc
->locinfo
->lconv
->int_curr_symbol
= MSVCRT_malloc(sizeof(char));
1310 loc
->locinfo
->lconv
->currency_symbol
= MSVCRT_malloc(sizeof(char));
1311 loc
->locinfo
->lconv
->mon_decimal_point
= MSVCRT_malloc(sizeof(char));
1312 loc
->locinfo
->lconv
->mon_thousands_sep
= MSVCRT_malloc(sizeof(char));
1313 loc
->locinfo
->lconv
->mon_grouping
= MSVCRT_malloc(sizeof(char));
1314 loc
->locinfo
->lconv
->positive_sign
= MSVCRT_malloc(sizeof(char));
1315 loc
->locinfo
->lconv
->negative_sign
= MSVCRT_malloc(sizeof(char));
1317 if(!loc
->locinfo
->lconv
->int_curr_symbol
|| !loc
->locinfo
->lconv
->currency_symbol
1318 || !loc
->locinfo
->lconv
->mon_decimal_point
|| !loc
->locinfo
->lconv
->mon_thousands_sep
1319 || !loc
->locinfo
->lconv
->mon_grouping
|| !loc
->locinfo
->lconv
->positive_sign
1320 || !loc
->locinfo
->lconv
->negative_sign
) {
1321 MSVCRT__free_locale(loc
);
1325 loc
->locinfo
->lconv
->int_curr_symbol
[0] = '\0';
1326 loc
->locinfo
->lconv
->currency_symbol
[0] = '\0';
1327 loc
->locinfo
->lconv
->mon_decimal_point
[0] = '\0';
1328 loc
->locinfo
->lconv
->mon_thousands_sep
[0] = '\0';
1329 loc
->locinfo
->lconv
->mon_grouping
[0] = '\0';
1330 loc
->locinfo
->lconv
->positive_sign
[0] = '\0';
1331 loc
->locinfo
->lconv
->negative_sign
[0] = '\0';
1332 loc
->locinfo
->lconv
->int_frac_digits
= 127;
1333 loc
->locinfo
->lconv
->frac_digits
= 127;
1334 loc
->locinfo
->lconv
->p_cs_precedes
= 127;
1335 loc
->locinfo
->lconv
->p_sep_by_space
= 127;
1336 loc
->locinfo
->lconv
->n_cs_precedes
= 127;
1337 loc
->locinfo
->lconv
->n_sep_by_space
= 127;
1338 loc
->locinfo
->lconv
->p_sign_posn
= 127;
1339 loc
->locinfo
->lconv
->n_sign_posn
= 127;
1341 #if _MSVCR_VER >= 120
1342 loc
->locinfo
->lconv
->_W_int_curr_symbol
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1343 loc
->locinfo
->lconv
->_W_currency_symbol
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1344 loc
->locinfo
->lconv
->_W_mon_decimal_point
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1345 loc
->locinfo
->lconv
->_W_mon_thousands_sep
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1346 loc
->locinfo
->lconv
->_W_positive_sign
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1347 loc
->locinfo
->lconv
->_W_negative_sign
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1349 if(!loc
->locinfo
->lconv
->_W_int_curr_symbol
|| !loc
->locinfo
->lconv
->_W_currency_symbol
1350 || !loc
->locinfo
->lconv
->_W_mon_decimal_point
|| !loc
->locinfo
->lconv
->_W_mon_thousands_sep
1351 || !loc
->locinfo
->lconv
->positive_sign
|| !loc
->locinfo
->lconv
->negative_sign
) {
1352 MSVCRT__free_locale(loc
);
1356 loc
->locinfo
->lconv
->_W_int_curr_symbol
[0] = '\0';
1357 loc
->locinfo
->lconv
->_W_currency_symbol
[0] = '\0';
1358 loc
->locinfo
->lconv
->_W_mon_decimal_point
[0] = '\0';
1359 loc
->locinfo
->lconv
->_W_mon_thousands_sep
[0] = '\0';
1360 loc
->locinfo
->lconv
->_W_positive_sign
[0] = '\0';
1361 loc
->locinfo
->lconv
->_W_negative_sign
[0] = '\0';
1364 loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
= MSVCRT__strdup("C");
1367 if(lcid
[MSVCRT_LC_NUMERIC
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_NUMERIC
)) {
1368 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_NUMERIC
], cp
[MSVCRT_LC_NUMERIC
], loc
, MSVCRT_LC_NUMERIC
)) {
1369 MSVCRT__free_locale(loc
);
1373 if(!loc
->locinfo
->lconv_intl_refcount
)
1374 loc
->locinfo
->lconv_intl_refcount
= MSVCRT_malloc(sizeof(int));
1375 loc
->locinfo
->lconv_num_refcount
= MSVCRT_malloc(sizeof(int));
1376 if(!loc
->locinfo
->lconv_intl_refcount
|| !loc
->locinfo
->lconv_num_refcount
) {
1377 MSVCRT__free_locale(loc
);
1381 *loc
->locinfo
->lconv_intl_refcount
= 1;
1382 *loc
->locinfo
->lconv_num_refcount
= 1;
1384 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SDECIMAL
1385 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1386 if(i
&& (loc
->locinfo
->lconv
->decimal_point
= MSVCRT_malloc(i
)))
1387 memcpy(loc
->locinfo
->lconv
->decimal_point
, buf
, i
);
1389 MSVCRT__free_locale(loc
);
1393 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_STHOUSAND
1394 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1395 if(i
&& (loc
->locinfo
->lconv
->thousands_sep
= MSVCRT_malloc(i
)))
1396 memcpy(loc
->locinfo
->lconv
->thousands_sep
, buf
, i
);
1398 MSVCRT__free_locale(loc
);
1402 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SGROUPING
1403 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1405 i
= i
/2 + (buf
[i
-2]=='0'?0:1);
1406 if(i
&& (loc
->locinfo
->lconv
->grouping
= MSVCRT_malloc(i
))) {
1407 for(i
=0; buf
[i
+1]==';'; i
+=2)
1408 loc
->locinfo
->lconv
->grouping
[i
/2] = buf
[i
]-'0';
1409 loc
->locinfo
->lconv
->grouping
[i
/2] = buf
[i
]-'0';
1411 loc
->locinfo
->lconv
->grouping
[i
/2+1] = 127;
1413 MSVCRT__free_locale(loc
);
1417 #if _MSVCR_VER >= 120
1418 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SDECIMAL
1419 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1420 if(i
&& (loc
->locinfo
->lconv
->_W_decimal_point
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1421 memcpy(loc
->locinfo
->lconv
->_W_decimal_point
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1423 MSVCRT__free_locale(loc
);
1427 i
= GetLocaleInfoW(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_STHOUSAND
1428 |LOCALE_NOUSEROVERRIDE
, wbuf
, 256);
1429 if(i
&& (loc
->locinfo
->lconv
->_W_thousands_sep
= MSVCRT_malloc(i
* sizeof(MSVCRT_wchar_t
))))
1430 memcpy(loc
->locinfo
->lconv
->_W_thousands_sep
, wbuf
, i
* sizeof(MSVCRT_wchar_t
));
1432 MSVCRT__free_locale(loc
);
1437 if(!set_lc_locale_name(loc
, MSVCRT_LC_NUMERIC
)) {
1438 MSVCRT__free_locale(loc
);
1442 loc
->locinfo
->lconv
->decimal_point
= MSVCRT_malloc(sizeof(char[2]));
1443 loc
->locinfo
->lconv
->thousands_sep
= MSVCRT_malloc(sizeof(char));
1444 loc
->locinfo
->lconv
->grouping
= MSVCRT_malloc(sizeof(char));
1445 if(!loc
->locinfo
->lconv
->decimal_point
|| !loc
->locinfo
->lconv
->thousands_sep
1446 || !loc
->locinfo
->lconv
->grouping
) {
1447 MSVCRT__free_locale(loc
);
1451 loc
->locinfo
->lconv
->decimal_point
[0] = '.';
1452 loc
->locinfo
->lconv
->decimal_point
[1] = '\0';
1453 loc
->locinfo
->lconv
->thousands_sep
[0] = '\0';
1454 loc
->locinfo
->lconv
->grouping
[0] = '\0';
1456 #if _MSVCR_VER >= 120
1457 loc
->locinfo
->lconv
->_W_decimal_point
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
[2]));
1458 loc
->locinfo
->lconv
->_W_thousands_sep
= MSVCRT_malloc(sizeof(MSVCRT_wchar_t
));
1460 if(!loc
->locinfo
->lconv
->_W_decimal_point
|| !loc
->locinfo
->lconv
->_W_thousands_sep
) {
1461 MSVCRT__free_locale(loc
);
1465 loc
->locinfo
->lconv
->_W_decimal_point
[0] = '.';
1466 loc
->locinfo
->lconv
->_W_decimal_point
[1] = '\0';
1467 loc
->locinfo
->lconv
->_W_thousands_sep
[0] = '\0';
1470 loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
= MSVCRT__strdup("C");
1473 if(lcid
[MSVCRT_LC_TIME
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_TIME
)) {
1474 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_TIME
], cp
[MSVCRT_LC_TIME
], loc
, MSVCRT_LC_TIME
)) {
1475 MSVCRT__free_locale(loc
);
1479 if(!set_lc_locale_name(loc
, MSVCRT_LC_TIME
)) {
1480 MSVCRT__free_locale(loc
);
1484 loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
= MSVCRT__strdup("C");
1486 size
= sizeof(MSVCRT___lc_time_data
);
1487 lcid_tmp
= lcid
[MSVCRT_LC_TIME
] ? lcid
[MSVCRT_LC_TIME
] : MAKELCID(LANG_ENGLISH
, SORT_DEFAULT
);
1488 for(i
=0; i
<sizeof(time_data
)/sizeof(time_data
[0]); i
++) {
1489 if(time_data
[i
]==LOCALE_SSHORTDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1490 size
+= sizeof(cloc_short_date
) + sizeof(cloc_short_dateW
);
1491 }else if(time_data
[i
]==LOCALE_SLONGDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1492 size
+= sizeof(cloc_long_date
) + sizeof(cloc_long_dateW
);
1494 ret
= GetLocaleInfoA(lcid_tmp
, time_data
[i
]
1495 |LOCALE_NOUSEROVERRIDE
, NULL
, 0);
1497 MSVCRT__free_locale(loc
);
1502 ret
= GetLocaleInfoW(lcid_tmp
, time_data
[i
]
1503 |LOCALE_NOUSEROVERRIDE
, NULL
, 0);
1505 MSVCRT__free_locale(loc
);
1508 size
+= ret
*sizeof(MSVCRT_wchar_t
);
1512 loc
->locinfo
->lc_time_curr
= MSVCRT_malloc(size
);
1513 if(!loc
->locinfo
->lc_time_curr
) {
1514 MSVCRT__free_locale(loc
);
1519 for(i
=0; i
<sizeof(time_data
)/sizeof(time_data
[0]); i
++) {
1520 loc
->locinfo
->lc_time_curr
->str
.str
[i
] = &loc
->locinfo
->lc_time_curr
->data
[ret
];
1521 if(time_data
[i
]==LOCALE_SSHORTDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1522 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_short_date
, sizeof(cloc_short_date
));
1523 ret
+= sizeof(cloc_short_date
);
1524 }else if(time_data
[i
]==LOCALE_SLONGDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1525 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_long_date
, sizeof(cloc_long_date
));
1526 ret
+= sizeof(cloc_long_date
);
1527 }else if(time_data
[i
]==LOCALE_STIMEFORMAT
&& !lcid
[MSVCRT_LC_TIME
]) {
1528 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_time
, sizeof(cloc_time
));
1529 ret
+= sizeof(cloc_time
);
1531 ret
+= GetLocaleInfoA(lcid_tmp
, time_data
[i
]|LOCALE_NOUSEROVERRIDE
,
1532 &loc
->locinfo
->lc_time_curr
->data
[ret
], size
-ret
);
1535 for(i
=0; i
<sizeof(time_data
)/sizeof(time_data
[0]); i
++) {
1536 loc
->locinfo
->lc_time_curr
->wstr
.wstr
[i
] = (MSVCRT_wchar_t
*)&loc
->locinfo
->lc_time_curr
->data
[ret
];
1537 if(time_data
[i
]==LOCALE_SSHORTDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1538 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_short_dateW
, sizeof(cloc_short_dateW
));
1539 ret
+= sizeof(cloc_short_dateW
);
1540 }else if(time_data
[i
]==LOCALE_SLONGDATE
&& !lcid
[MSVCRT_LC_TIME
]) {
1541 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_long_dateW
, sizeof(cloc_long_dateW
));
1542 ret
+= sizeof(cloc_long_dateW
);
1543 }else if(time_data
[i
]==LOCALE_STIMEFORMAT
&& !lcid
[MSVCRT_LC_TIME
]) {
1544 memcpy(&loc
->locinfo
->lc_time_curr
->data
[ret
], cloc_timeW
, sizeof(cloc_timeW
));
1545 ret
+= sizeof(cloc_timeW
);
1547 ret
+= GetLocaleInfoW(lcid_tmp
, time_data
[i
]|LOCALE_NOUSEROVERRIDE
,
1548 (MSVCRT_wchar_t
*)&loc
->locinfo
->lc_time_curr
->data
[ret
], size
-ret
)*sizeof(MSVCRT_wchar_t
);
1551 loc
->locinfo
->lc_time_curr
->lcid
= lcid
[MSVCRT_LC_TIME
];
1556 /*********************************************************************
1557 * setlocale (MSVCRT.@)
1559 char* CDECL
MSVCRT_setlocale(int category
, const char* locale
)
1561 MSVCRT__locale_t loc
;
1562 MSVCRT_pthreadlocinfo locinfo
= get_locinfo();
1564 if(category
<MSVCRT_LC_MIN
|| category
>MSVCRT_LC_MAX
)
1568 if(category
== MSVCRT_LC_ALL
)
1569 return construct_lc_all(locinfo
);
1571 return locinfo
->lc_category
[category
].locale
;
1574 loc
= MSVCRT__create_locale(category
, locale
);
1576 WARN("%d %s failed\n", category
, locale
);
1584 case MSVCRT_LC_COLLATE
:
1585 locinfo
->lc_collate_cp
= loc
->locinfo
->lc_collate_cp
;
1586 locinfo
->lc_handle
[MSVCRT_LC_COLLATE
] =
1587 loc
->locinfo
->lc_handle
[MSVCRT_LC_COLLATE
];
1588 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
,
1589 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
);
1590 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_COLLATE
].refcount
,
1591 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].refcount
);
1593 #if _MSVCR_VER >= 110
1594 swap_pointers((void**)&locinfo
->lc_name
[MSVCRT_LC_COLLATE
],
1595 (void**)&loc
->locinfo
->lc_name
[MSVCRT_LC_COLLATE
]);
1598 if(category
!= MSVCRT_LC_ALL
)
1601 case MSVCRT_LC_CTYPE
:
1602 locinfo
->lc_handle
[MSVCRT_LC_CTYPE
] =
1603 loc
->locinfo
->lc_handle
[MSVCRT_LC_CTYPE
];
1604 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
,
1605 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
);
1606 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_CTYPE
].refcount
,
1607 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].refcount
);
1609 locinfo
->lc_codepage
= loc
->locinfo
->lc_codepage
;
1610 locinfo
->lc_clike
= loc
->locinfo
->lc_clike
;
1611 locinfo
->mb_cur_max
= loc
->locinfo
->mb_cur_max
;
1613 swap_pointers((void**)&locinfo
->ctype1_refcount
,
1614 (void**)&loc
->locinfo
->ctype1_refcount
);
1615 swap_pointers((void**)&locinfo
->ctype1
, (void**)&loc
->locinfo
->ctype1
);
1616 swap_pointers((void**)&locinfo
->pctype
, (void**)&loc
->locinfo
->pctype
);
1617 swap_pointers((void**)&locinfo
->pclmap
, (void**)&loc
->locinfo
->pclmap
);
1618 swap_pointers((void**)&locinfo
->pcumap
, (void**)&loc
->locinfo
->pcumap
);
1620 #if _MSVCR_VER >= 110
1621 swap_pointers((void**)&locinfo
->lc_name
[MSVCRT_LC_CTYPE
],
1622 (void**)&loc
->locinfo
->lc_name
[MSVCRT_LC_CTYPE
]);
1625 if(category
!= MSVCRT_LC_ALL
)
1628 case MSVCRT_LC_MONETARY
:
1629 locinfo
->lc_handle
[MSVCRT_LC_MONETARY
] =
1630 loc
->locinfo
->lc_handle
[MSVCRT_LC_MONETARY
];
1631 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
,
1632 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
);
1633 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_MONETARY
].refcount
,
1634 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].refcount
);
1636 swap_pointers((void**)&locinfo
->lconv
->int_curr_symbol
,
1637 (void**)&loc
->locinfo
->lconv
->int_curr_symbol
);
1638 swap_pointers((void**)&locinfo
->lconv
->currency_symbol
,
1639 (void**)&loc
->locinfo
->lconv
->currency_symbol
);
1640 swap_pointers((void**)&locinfo
->lconv
->mon_decimal_point
,
1641 (void**)&loc
->locinfo
->lconv
->mon_decimal_point
);
1642 swap_pointers((void**)&locinfo
->lconv
->mon_thousands_sep
,
1643 (void**)&loc
->locinfo
->lconv
->mon_thousands_sep
);
1644 swap_pointers((void**)&locinfo
->lconv
->mon_grouping
,
1645 (void**)&loc
->locinfo
->lconv
->mon_grouping
);
1646 swap_pointers((void**)&locinfo
->lconv
->positive_sign
,
1647 (void**)&loc
->locinfo
->lconv
->positive_sign
);
1648 swap_pointers((void**)&locinfo
->lconv
->negative_sign
,
1649 (void**)&loc
->locinfo
->lconv
->negative_sign
);
1651 #if _MSVCR_VER >= 120
1652 swap_pointers((void**)&locinfo
->lconv
->_W_int_curr_symbol
,
1653 (void**)&loc
->locinfo
->lconv
->_W_int_curr_symbol
);
1654 swap_pointers((void**)&locinfo
->lconv
->_W_currency_symbol
,
1655 (void**)&loc
->locinfo
->lconv
->_W_currency_symbol
);
1656 swap_pointers((void**)&locinfo
->lconv
->_W_mon_decimal_point
,
1657 (void**)&loc
->locinfo
->lconv
->_W_mon_decimal_point
);
1658 swap_pointers((void**)&locinfo
->lconv
->_W_mon_thousands_sep
,
1659 (void**)&loc
->locinfo
->lconv
->_W_mon_thousands_sep
);
1660 swap_pointers((void**)&locinfo
->lconv
->_W_positive_sign
,
1661 (void**)&loc
->locinfo
->lconv
->_W_positive_sign
);
1662 swap_pointers((void**)&locinfo
->lconv
->_W_negative_sign
,
1663 (void**)&loc
->locinfo
->lconv
->_W_negative_sign
);
1666 locinfo
->lconv
->int_frac_digits
= loc
->locinfo
->lconv
->int_frac_digits
;
1667 locinfo
->lconv
->frac_digits
= loc
->locinfo
->lconv
->frac_digits
;
1668 locinfo
->lconv
->p_cs_precedes
= loc
->locinfo
->lconv
->p_cs_precedes
;
1669 locinfo
->lconv
->p_sep_by_space
= loc
->locinfo
->lconv
->p_sep_by_space
;
1670 locinfo
->lconv
->n_cs_precedes
= loc
->locinfo
->lconv
->n_cs_precedes
;
1671 locinfo
->lconv
->n_sep_by_space
= loc
->locinfo
->lconv
->n_sep_by_space
;
1672 locinfo
->lconv
->p_sign_posn
= loc
->locinfo
->lconv
->p_sign_posn
;
1673 locinfo
->lconv
->n_sign_posn
= loc
->locinfo
->lconv
->n_sign_posn
;
1675 #if _MSVCR_VER >= 110
1676 swap_pointers((void**)&locinfo
->lc_name
[MSVCRT_LC_MONETARY
],
1677 (void**)&loc
->locinfo
->lc_name
[MSVCRT_LC_MONETARY
]);
1680 if(category
!= MSVCRT_LC_ALL
)
1683 case MSVCRT_LC_NUMERIC
:
1684 locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
] =
1685 loc
->locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
];
1686 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
,
1687 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
);
1688 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].refcount
,
1689 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].refcount
);
1691 swap_pointers((void**)&locinfo
->lconv
->decimal_point
,
1692 (void**)&loc
->locinfo
->lconv
->decimal_point
);
1693 swap_pointers((void**)&locinfo
->lconv
->thousands_sep
,
1694 (void**)&loc
->locinfo
->lconv
->thousands_sep
);
1695 swap_pointers((void**)&locinfo
->lconv
->grouping
,
1696 (void**)&loc
->locinfo
->lconv
->grouping
);
1698 #if _MSVCR_VER >= 120
1699 swap_pointers((void**)&locinfo
->lconv
->_W_decimal_point
,
1700 (void**)&loc
->locinfo
->lconv
->_W_decimal_point
);
1701 swap_pointers((void**)&locinfo
->lconv
->_W_thousands_sep
,
1702 (void**)&loc
->locinfo
->lconv
->_W_thousands_sep
);
1705 #if _MSVCR_VER >= 110
1706 swap_pointers((void**)&locinfo
->lc_name
[MSVCRT_LC_NUMERIC
],
1707 (void**)&loc
->locinfo
->lc_name
[MSVCRT_LC_NUMERIC
]);
1710 if(category
!= MSVCRT_LC_ALL
)
1713 case MSVCRT_LC_TIME
:
1714 locinfo
->lc_handle
[MSVCRT_LC_TIME
] =
1715 loc
->locinfo
->lc_handle
[MSVCRT_LC_TIME
];
1716 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
,
1717 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
);
1718 swap_pointers((void**)&locinfo
->lc_category
[MSVCRT_LC_TIME
].refcount
,
1719 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].refcount
);
1720 swap_pointers((void**)&locinfo
->lc_time_curr
,
1721 (void**)&loc
->locinfo
->lc_time_curr
);
1723 #if _MSVCR_VER >= 110
1724 swap_pointers((void**)&locinfo
->lc_name
[MSVCRT_LC_TIME
],
1725 (void**)&loc
->locinfo
->lc_name
[MSVCRT_LC_TIME
]);
1728 if(category
!= MSVCRT_LC_ALL
)
1732 MSVCRT__free_locale(loc
);
1735 if(locinfo
== MSVCRT_locale
->locinfo
) {
1738 MSVCRT___lc_codepage
= locinfo
->lc_codepage
;
1739 MSVCRT___lc_collate_cp
= locinfo
->lc_collate_cp
;
1740 MSVCRT___mb_cur_max
= locinfo
->mb_cur_max
;
1741 MSVCRT__pctype
= locinfo
->pctype
;
1742 for(i
=MSVCRT_LC_MIN
; i
<=MSVCRT_LC_MAX
; i
++)
1743 MSVCRT___lc_handle
[i
] = MSVCRT_locale
->locinfo
->lc_handle
[i
];
1746 if(category
== MSVCRT_LC_ALL
)
1747 return construct_lc_all(locinfo
);
1749 return locinfo
->lc_category
[category
].locale
;
1752 /*********************************************************************
1753 * _wsetlocale (MSVCRT.@)
1755 MSVCRT_wchar_t
* CDECL
MSVCRT__wsetlocale(int category
, const MSVCRT_wchar_t
* wlocale
)
1757 static MSVCRT_wchar_t current_lc_all
[MAX_LOCALE_LENGTH
];
1759 char *locale
= NULL
;
1764 len
= MSVCRT_wcstombs(NULL
, wlocale
, 0);
1768 locale
= MSVCRT_malloc(++len
);
1772 MSVCRT_wcstombs(locale
, wlocale
, len
);
1776 ret
= MSVCRT_setlocale(category
, locale
);
1777 MSVCRT_free(locale
);
1779 if(ret
&& MSVCRT_mbstowcs(current_lc_all
, ret
, MAX_LOCALE_LENGTH
)==-1)
1783 return ret
? current_lc_all
: NULL
;
1786 /*********************************************************************
1787 * _configthreadlocale (MSVCR80.@)
1789 int CDECL
_configthreadlocale(int type
)
1791 thread_data_t
*data
= msvcrt_get_thread_data();
1792 MSVCRT__locale_t locale
;
1798 ret
= (data
->have_locale
? MSVCRT__ENABLE_PER_THREAD_LOCALE
: MSVCRT__DISABLE_PER_THREAD_LOCALE
);
1800 if(type
== MSVCRT__ENABLE_PER_THREAD_LOCALE
) {
1801 if(!data
->have_locale
) {
1802 /* Copy current global locale */
1803 locale
= MSVCRT__create_locale(MSVCRT_LC_ALL
, MSVCRT_setlocale(MSVCRT_LC_ALL
, NULL
));
1807 data
->locinfo
= locale
->locinfo
;
1808 data
->mbcinfo
= locale
->mbcinfo
;
1809 data
->have_locale
= TRUE
;
1810 MSVCRT_free(locale
);
1816 if(type
== MSVCRT__DISABLE_PER_THREAD_LOCALE
) {
1817 if(data
->have_locale
) {
1818 free_locinfo(data
->locinfo
);
1819 free_mbcinfo(data
->mbcinfo
);
1820 data
->locinfo
= MSVCRT_locale
->locinfo
;
1821 data
->mbcinfo
= MSVCRT_locale
->mbcinfo
;
1822 data
->have_locale
= FALSE
;
1834 BOOL
msvcrt_init_locale(void)
1839 MSVCRT_locale
= MSVCRT__create_locale(0, "C");
1844 MSVCRT___lc_codepage
= MSVCRT_locale
->locinfo
->lc_codepage
;
1845 MSVCRT___lc_collate_cp
= MSVCRT_locale
->locinfo
->lc_collate_cp
;
1846 MSVCRT___mb_cur_max
= MSVCRT_locale
->locinfo
->mb_cur_max
;
1847 MSVCRT__pctype
= MSVCRT_locale
->locinfo
->pctype
;
1848 for(i
=MSVCRT_LC_MIN
; i
<=MSVCRT_LC_MAX
; i
++)
1849 MSVCRT___lc_handle
[i
] = MSVCRT_locale
->locinfo
->lc_handle
[i
];
1850 _setmbcp(_MB_CP_ANSI
);