2 * msvcrt.dll locale functions
4 * Copyright 2000 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
41 #define MAX_ELEM_LEN 64 /* Max length of country/language/CP string */
42 #define MAX_LOCALE_LENGTH 256
43 MSVCRT__locale_t MSVCRT_locale
= NULL
;
44 int MSVCRT___lc_codepage
= 0;
45 int MSVCRT___lc_collate_cp
= 0;
46 HANDLE MSVCRT___lc_handle
[MSVCRT_LC_MAX
- MSVCRT_LC_MIN
+ 1] = { 0 };
47 unsigned char charmax
= CHAR_MAX
;
50 #define LOCK_LOCALE _mlock(_SETLOCALE_LOCK);
51 #define UNLOCK_LOCALE _munlock(_SETLOCALE_LOCK);
53 #define MSVCRT_LEADBYTE 0x8000
54 #define MSVCRT_C1_DEFINED 0x200
56 /* Friendly country strings & language names abbreviations. */
57 static const char * const _country_synonyms
[] =
60 "american english", "enu",
61 "american-english", "enu",
62 "english-american", "enu",
70 "french-belgian", "frb",
73 "french-canadian", "frc",
75 "chinese-simplified", "chs",
76 "chinese-traditional", "cht",
77 "dutch-belgian", "nlb",
81 "french-swiss", "frs",
83 "german-swiss", "des",
84 "italian-swiss", "its",
85 "german-austrian", "dea",
87 "portuguese-brazil", "ptb",
88 "spanish-mexican", "esm",
89 "norwegian-bokmal", "nor",
90 "norwegian-nynorsk", "non",
91 "spanish-modern", "esn"
94 /* INTERNAL: Map a synonym to an ISO code */
95 static void remap_synonym(char *name
)
98 for (i
= 0; i
< sizeof(_country_synonyms
)/sizeof(char*); i
+= 2 )
100 if (!strcasecmp(_country_synonyms
[i
],name
))
102 TRACE(":Mapping synonym %s to %s\n",name
,_country_synonyms
[i
+1]);
103 memcpy(name
, _country_synonyms
[i
+1], sizeof(_country_synonyms
[i
+1]));
109 /* Note: Flags are weighted in order of matching importance */
110 #define FOUND_LANGUAGE 0x4
111 #define FOUND_COUNTRY 0x2
112 #define FOUND_CODEPAGE 0x1
115 char search_language
[MAX_ELEM_LEN
];
116 char search_country
[MAX_ELEM_LEN
];
117 char search_codepage
[MAX_ELEM_LEN
];
118 char found_codepage
[MAX_ELEM_LEN
];
119 unsigned int match_flags
;
120 LANGID found_lang_id
;
123 #define CONTINUE_LOOKING TRUE
124 #define STOP_LOOKING FALSE
126 /* INTERNAL: Get and compare locale info with a given string */
127 static int compare_info(LCID lcid
, DWORD flags
, char* buff
, const char* cmp
, BOOL exact
)
132 GetLocaleInfoA(lcid
, flags
|LOCALE_NOUSEROVERRIDE
, buff
, MAX_ELEM_LEN
);
133 if (!buff
[0] || !cmp
[0])
136 /* Partial matches are only allowed on language/country names */
139 return !strcasecmp(cmp
, buff
);
141 return !strncasecmp(cmp
, buff
, len
);
145 find_best_locale_proc(HMODULE hModule
, LPCSTR type
, LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
147 locale_search_t
*res
= (locale_search_t
*)lParam
;
148 const LCID lcid
= MAKELCID(LangID
, SORT_DEFAULT
);
149 char buff
[MAX_ELEM_LEN
];
150 unsigned int flags
= 0;
152 if(PRIMARYLANGID(LangID
) == LANG_NEUTRAL
)
153 return CONTINUE_LOOKING
;
156 if (compare_info(lcid
,LOCALE_SISO639LANGNAME
,buff
,res
->search_language
, TRUE
) ||
157 compare_info(lcid
,LOCALE_SABBREVLANGNAME
,buff
,res
->search_language
, TRUE
) ||
158 compare_info(lcid
,LOCALE_SENGLANGUAGE
,buff
,res
->search_language
, FALSE
))
160 TRACE(":Found language: %s->%s\n", res
->search_language
, buff
);
161 flags
|= FOUND_LANGUAGE
;
163 else if (res
->match_flags
& FOUND_LANGUAGE
)
165 return CONTINUE_LOOKING
;
169 if (compare_info(lcid
,LOCALE_SISO3166CTRYNAME
,buff
,res
->search_country
, TRUE
) ||
170 compare_info(lcid
,LOCALE_SABBREVCTRYNAME
,buff
,res
->search_country
, TRUE
) ||
171 compare_info(lcid
,LOCALE_SENGCOUNTRY
,buff
,res
->search_country
, FALSE
))
173 TRACE("Found country:%s->%s\n", res
->search_country
, buff
);
174 flags
|= FOUND_COUNTRY
;
176 else if (res
->match_flags
& FOUND_COUNTRY
)
178 return CONTINUE_LOOKING
;
182 if (compare_info(lcid
,LOCALE_IDEFAULTCODEPAGE
,buff
,res
->search_codepage
, TRUE
) ||
183 (compare_info(lcid
,LOCALE_IDEFAULTANSICODEPAGE
,buff
,res
->search_codepage
, TRUE
)))
185 TRACE("Found codepage:%s->%s\n", res
->search_codepage
, buff
);
186 flags
|= FOUND_CODEPAGE
;
187 memcpy(res
->found_codepage
,res
->search_codepage
,MAX_ELEM_LEN
);
189 else if (res
->match_flags
& FOUND_CODEPAGE
)
191 return CONTINUE_LOOKING
;
194 if (flags
> res
->match_flags
)
196 /* Found a better match than previously */
197 res
->match_flags
= flags
;
198 res
->found_lang_id
= LangID
;
200 if ((flags
& (FOUND_LANGUAGE
| FOUND_COUNTRY
| FOUND_CODEPAGE
)) ==
201 (FOUND_LANGUAGE
| FOUND_COUNTRY
| FOUND_CODEPAGE
))
203 TRACE(":found exact locale match\n");
206 return CONTINUE_LOOKING
;
209 extern int atoi(const char *);
211 /* Internal: Find the LCID for a locale specification */
212 static LCID
MSVCRT_locale_to_LCID(const char *locale
)
215 locale_search_t search
;
218 memset(&search
, 0, sizeof(locale_search_t
));
220 cp
= strchr(locale
, '.');
221 region
= strchr(locale
, '_');
223 lstrcpynA(search
.search_language
, locale
, MAX_ELEM_LEN
);
225 lstrcpynA(search
.search_country
, region
+1, MAX_ELEM_LEN
);
226 if(region
-locale
< MAX_ELEM_LEN
)
227 search
.search_language
[region
-locale
] = '\0';
229 search
.search_country
[0] = '\0';
232 lstrcpynA(search
.search_codepage
, cp
+1, MAX_ELEM_LEN
);
233 if(cp
-region
-1 < MAX_ELEM_LEN
)
234 search
.search_country
[cp
-region
-1] = '\0';
235 if(cp
-locale
< MAX_ELEM_LEN
)
236 search
.search_language
[cp
-locale
] = '\0';
238 search
.search_codepage
[0] = '\0';
240 if(!search
.search_country
[0] && !search
.search_codepage
[0])
241 remap_synonym(search
.search_language
);
243 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), (LPSTR
)RT_STRING
,
244 (LPCSTR
)LOCALE_ILANGUAGE
,find_best_locale_proc
,
247 if (!search
.match_flags
)
250 /* If we were given something that didn't match, fail */
251 if (search
.search_country
[0] && !(search
.match_flags
& FOUND_COUNTRY
))
254 lcid
= MAKELCID(search
.found_lang_id
, SORT_DEFAULT
);
256 /* Populate partial locale, translating LCID to locale string elements */
257 if (!search
.found_codepage
[0]) {
258 /* Even if a codepage is not enumerated for a locale
259 * it can be set if valid */
260 if (search
.search_codepage
[0]) {
261 if (IsValidCodePage(atoi(search
.search_codepage
)))
262 memcpy(search
.found_codepage
,search
.search_codepage
,MAX_ELEM_LEN
);
264 /* Special codepage values: OEM & ANSI */
265 if (strcasecmp(search
.search_codepage
,"OCP")) {
266 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTCODEPAGE
,
267 search
.found_codepage
, MAX_ELEM_LEN
);
268 } else if (strcasecmp(search
.search_codepage
,"ACP")) {
269 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
,
270 search
.found_codepage
, MAX_ELEM_LEN
);
274 if (!atoi(search
.found_codepage
))
278 /* Prefer ANSI codepages if present */
279 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
,
280 search
.found_codepage
, MAX_ELEM_LEN
);
281 if (!search
.found_codepage
[0] || !atoi(search
.found_codepage
))
282 GetLocaleInfoA(lcid
, LOCALE_IDEFAULTCODEPAGE
,
283 search
.found_codepage
, MAX_ELEM_LEN
);
290 /* INTERNAL: Set lc_handle, lc_id and lc_category in threadlocinfo struct */
291 static BOOL
update_threadlocinfo_category(LCID lcid
, MSVCRT__locale_t loc
, int category
)
296 if(GetLocaleInfoA(lcid
, LOCALE_ILANGUAGE
|LOCALE_NOUSEROVERRIDE
, buf
, 256)) {
299 loc
->locinfo
->lc_id
[category
].wLanguage
= 0;
301 loc
->locinfo
->lc_id
[category
].wLanguage
*= 16;
304 loc
->locinfo
->lc_id
[category
].wLanguage
+= *p
-'0';
306 loc
->locinfo
->lc_id
[category
].wLanguage
+= *p
-'a'+10;
311 loc
->locinfo
->lc_id
[category
].wCountry
=
312 loc
->locinfo
->lc_id
[category
].wLanguage
;
315 if(GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
316 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
317 loc
->locinfo
->lc_id
[category
].wCodePage
= atoi(buf
);
319 loc
->locinfo
->lc_handle
[category
] = lcid
;
322 len
+= GetLocaleInfoA(lcid
, LOCALE_SENGLANGUAGE
323 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
325 len
+= GetLocaleInfoA(lcid
, LOCALE_SENGCOUNTRY
326 |LOCALE_NOUSEROVERRIDE
, &buf
[len
], 256-len
);
328 len
+= GetLocaleInfoA(lcid
, LOCALE_IDEFAULTANSICODEPAGE
329 |LOCALE_NOUSEROVERRIDE
, &buf
[len
], 256-len
);
331 loc
->locinfo
->lc_category
[category
].locale
= MSVCRT_malloc(sizeof(char[len
]));
332 loc
->locinfo
->lc_category
[category
].refcount
= MSVCRT_malloc(sizeof(int));
333 if(!loc
->locinfo
->lc_category
[category
].locale
334 || !loc
->locinfo
->lc_category
[category
].refcount
) {
335 MSVCRT_free(loc
->locinfo
->lc_category
[category
].locale
);
336 MSVCRT_free(loc
->locinfo
->lc_category
[category
].refcount
);
337 loc
->locinfo
->lc_category
[category
].locale
= NULL
;
338 loc
->locinfo
->lc_category
[category
].refcount
= NULL
;
341 memcpy(loc
->locinfo
->lc_category
[category
].locale
, buf
, sizeof(char[len
]));
342 *loc
->locinfo
->lc_category
[category
].refcount
= 1;
347 /* INTERNAL: swap pointers values */
348 static inline void swap_pointers(void **p1
, void **p2
) {
356 /* INTERNAL: returns _locale_t struct for current locale */
357 MSVCRT__locale_t
get_locale(void) {
358 thread_data_t
*data
= msvcrt_get_thread_data();
360 if(!data
|| !data
->locale
)
361 return MSVCRT_locale
;
366 /* INTERNAL: constructs string returned by setlocale */
367 static inline char* construct_lc_all(MSVCRT__locale_t cur
) {
368 static char current_lc_all
[MAX_LOCALE_LENGTH
];
372 for(i
=MSVCRT_LC_MIN
+1; i
<MSVCRT_LC_MAX
; i
++) {
373 if(strcmp(cur
->locinfo
->lc_category
[i
].locale
,
374 cur
->locinfo
->lc_category
[i
+1].locale
))
379 return cur
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
;
381 sprintf(current_lc_all
,
382 "LC_COLLATE=%s;LC_CTYPE=%s;LC_MONETARY=%s;LC_NUMERIC=%s;LC_TIME=%s",
383 cur
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
,
384 cur
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
,
385 cur
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
,
386 cur
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
,
387 cur
->locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
);
389 return current_lc_all
;
393 /*********************************************************************
394 * wsetlocale (MSVCRT.@)
396 MSVCRT_wchar_t
* CDECL
MSVCRT__wsetlocale(int category
, const MSVCRT_wchar_t
* locale
)
398 static MSVCRT_wchar_t fake
[] = {
399 'E','n','g','l','i','s','h','_','U','n','i','t','e','d',' ',
400 'S','t','a','t','e','s','.','1','2','5','2',0 };
402 FIXME("%d %s\n", category
, debugstr_w(locale
));
407 /*********************************************************************
408 * _Getdays (MSVCRT.@)
410 const char* CDECL
_Getdays(void)
412 static const char MSVCRT_days
[] = ":Sun:Sunday:Mon:Monday:Tue:Tuesday:Wed:"
413 "Wednesday:Thu:Thursday:Fri:Friday:Sat:Saturday";
414 /* FIXME: Use locale */
415 TRACE("(void) semi-stub\n");
419 /*********************************************************************
420 * _Getmonths (MSVCRT.@)
422 const char* CDECL
_Getmonths(void)
424 static const char MSVCRT_months
[] = ":Jan:January:Feb:February:Mar:March:Apr:"
425 "April:May:May:Jun:June:Jul:July:Aug:August:Sep:September:Oct:"
426 "October:Nov:November:Dec:December";
427 /* FIXME: Use locale */
428 TRACE("(void) semi-stub\n");
429 return MSVCRT_months
;
432 /*********************************************************************
433 * _Gettnames (MSVCRT.@)
435 const char* CDECL
_Gettnames(void)
438 TRACE("(void) stub\n");
442 /*********************************************************************
443 * _Strftime (MSVCRT.@)
445 const char* CDECL
_Strftime(char *out
, unsigned int len
, const char *fmt
,
446 const void *tm
, void *foo
)
449 TRACE("(%p %d %s %p %p) stub\n", out
, len
, fmt
, tm
, foo
);
453 /*********************************************************************
454 * __crtLCMapStringA (MSVCRT.@)
456 int CDECL
__crtLCMapStringA(
457 LCID lcid
, DWORD mapflags
, const char* src
, int srclen
, char* dst
,
458 int dstlen
, unsigned int codepage
, int xflag
460 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
461 lcid
,mapflags
,src
,srclen
,dst
,dstlen
,codepage
,xflag
);
462 /* FIXME: A bit incorrect. But msvcrt itself just converts its
463 * arguments to wide strings and then calls LCMapStringW
465 return LCMapStringA(lcid
,mapflags
,src
,srclen
,dst
,dstlen
);
468 /*********************************************************************
469 * __crtLCMapStringW (MSVCRT.@)
471 int CDECL
__crtLCMapStringW(LCID lcid
, DWORD mapflags
, const MSVCRT_wchar_t
*src
,
472 int srclen
, MSVCRT_wchar_t
*dst
, int dstlen
, unsigned int codepage
, int xflag
)
474 FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
475 lcid
, mapflags
, debugstr_w(src
), srclen
, dst
, dstlen
, codepage
, xflag
);
477 return LCMapStringW(lcid
, mapflags
, src
, srclen
, dst
, dstlen
);
480 /*********************************************************************
481 * __crtCompareStringA (MSVCRT.@)
483 int CDECL
__crtCompareStringA( LCID lcid
, DWORD flags
, const char *src1
, int len1
,
484 const char *src2
, int len2
)
486 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
487 lcid
, flags
, debugstr_a(src1
), len1
, debugstr_a(src2
), len2
);
488 /* FIXME: probably not entirely right */
489 return CompareStringA( lcid
, flags
, src1
, len1
, src2
, len2
);
492 /*********************************************************************
493 * __crtCompareStringW (MSVCRT.@)
495 int CDECL
__crtCompareStringW( LCID lcid
, DWORD flags
, const MSVCRT_wchar_t
*src1
, int len1
,
496 const MSVCRT_wchar_t
*src2
, int len2
)
498 FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
499 lcid
, flags
, debugstr_w(src1
), len1
, debugstr_w(src2
), len2
);
500 /* FIXME: probably not entirely right */
501 return CompareStringW( lcid
, flags
, src1
, len1
, src2
, len2
);
504 /*********************************************************************
505 * __crtGetLocaleInfoW (MSVCRT.@)
507 int CDECL
__crtGetLocaleInfoW( LCID lcid
, LCTYPE type
, MSVCRT_wchar_t
*buffer
, int len
)
509 FIXME("(lcid %x, type %x, %p(%d), partial stub\n", lcid
, type
, buffer
, len
);
510 /* FIXME: probably not entirely right */
511 return GetLocaleInfoW( lcid
, type
, buffer
, len
);
514 /*********************************************************************
517 MSVCRT_wint_t CDECL
MSVCRT_btowc(int c
)
519 MSVCRT__locale_t locale
= get_locale();
520 unsigned char letter
= c
;
523 if(!MultiByteToWideChar(locale
->locinfo
->lc_handle
[MSVCRT_LC_CTYPE
],
524 0, (LPCSTR
)&letter
, 1, &ret
, 1))
530 /*********************************************************************
531 * __crtGetStringTypeW(MSVCRT.@)
533 * This function was accepting different number of arguments in older
534 * versions of msvcrt.
536 BOOL CDECL
__crtGetStringTypeW(DWORD unk
, DWORD type
,
537 MSVCRT_wchar_t
*buffer
, int len
, WORD
*out
)
539 FIXME("(unk %x, type %x, wstr %p(%d), %p) partial stub\n",
540 unk
, type
, buffer
, len
, out
);
542 return GetStringTypeW(type
, buffer
, len
, out
);
545 /*********************************************************************
546 * localeconv (MSVCRT.@)
548 struct MSVCRT_lconv
* CDECL
MSVCRT_localeconv(void)
550 return get_locale()->locinfo
->lconv
;
553 /*********************************************************************
554 * __lconv_init (MSVCRT.@)
556 int CDECL
__lconv_init(void)
558 /* this is used to make chars unsigned */
563 /*********************************************************************
564 * ___lc_handle_func (MSVCRT.@)
566 HANDLE
* CDECL
___lc_handle_func(void)
568 return MSVCRT___lc_handle
;
571 /*********************************************************************
572 * ___lc_codepage_func (MSVCRT.@)
574 int CDECL
___lc_codepage_func(void)
576 return MSVCRT___lc_codepage
;
579 /*********************************************************************
580 * ___lc_collate_cp_func (MSVCRT.@)
582 int CDECL
___lc_collate_cp_func(void)
584 return get_locale()->locinfo
->lc_collate_cp
;
587 /* _free_locale - not exported in native msvcrt */
588 void CDECL
MSVCRT__free_locale(MSVCRT__locale_t locale
)
595 for(i
=MSVCRT_LC_MIN
+1; i
<=MSVCRT_LC_MAX
; i
++) {
596 MSVCRT_free(locale
->locinfo
->lc_category
[i
].locale
);
597 MSVCRT_free(locale
->locinfo
->lc_category
[i
].refcount
);
600 if(locale
->locinfo
->lconv
) {
601 MSVCRT_free(locale
->locinfo
->lconv
->decimal_point
);
602 MSVCRT_free(locale
->locinfo
->lconv
->thousands_sep
);
603 MSVCRT_free(locale
->locinfo
->lconv
->grouping
);
604 MSVCRT_free(locale
->locinfo
->lconv
->int_curr_symbol
);
605 MSVCRT_free(locale
->locinfo
->lconv
->currency_symbol
);
606 MSVCRT_free(locale
->locinfo
->lconv
->mon_decimal_point
);
607 MSVCRT_free(locale
->locinfo
->lconv
->mon_thousands_sep
);
608 MSVCRT_free(locale
->locinfo
->lconv
->mon_grouping
);
609 MSVCRT_free(locale
->locinfo
->lconv
->positive_sign
);
610 MSVCRT_free(locale
->locinfo
->lconv
->negative_sign
);
612 MSVCRT_free(locale
->locinfo
->lconv_intl_refcount
);
613 MSVCRT_free(locale
->locinfo
->lconv_num_refcount
);
614 MSVCRT_free(locale
->locinfo
->lconv_mon_refcount
);
615 MSVCRT_free(locale
->locinfo
->lconv
);
617 MSVCRT_free(locale
->locinfo
->ctype1_refcount
);
618 MSVCRT_free(locale
->locinfo
->ctype1
);
620 MSVCRT_free(locale
->locinfo
->pclmap
);
621 MSVCRT_free(locale
->locinfo
->pcumap
);
623 MSVCRT_free(locale
->locinfo
);
624 MSVCRT_free(locale
->mbcinfo
);
628 /* _create_locale - not exported in native msvcrt */
629 MSVCRT__locale_t
MSVCRT__create_locale(int category
, const char *locale
)
631 static const char collate
[] = "COLLATE=";
632 static const char ctype
[] = "CTYPE=";
633 static const char monetary
[] = "MONETARY=";
634 static const char numeric
[] = "NUMERIC=";
635 static const char time
[] = "TIME=";
637 MSVCRT__locale_t loc
;
638 LCID lcid
[6] = { 0 };
642 TRACE("(%d %s)\n", category
, locale
);
644 if(category
<MSVCRT_LC_MIN
|| category
>MSVCRT_LC_MAX
|| !locale
)
647 if(locale
[0]=='C' && !locale
[1])
650 lcid
[0] = GetSystemDefaultLCID();
651 else if (locale
[0] == 'L' && locale
[1] == 'C' && locale
[2] == '_') {
655 locale
+= 3; /* LC_ */
656 if(!memcmp(locale
, collate
, sizeof(collate
)-1)) {
657 i
= MSVCRT_LC_COLLATE
;
658 locale
+= sizeof(collate
)-1;
659 } else if(!memcmp(locale
, ctype
, sizeof(ctype
)-1)) {
661 locale
+= sizeof(ctype
)-1;
662 } else if(!memcmp(locale
, monetary
, sizeof(monetary
)-1)) {
663 i
= MSVCRT_LC_MONETARY
;
664 locale
+= sizeof(monetary
)-1;
665 } else if(!memcmp(locale
, numeric
, sizeof(numeric
)-1)) {
666 i
= MSVCRT_LC_NUMERIC
;
667 locale
+= sizeof(numeric
)-1;
668 } else if(!memcmp(locale
, time
, sizeof(time
)-1)) {
670 locale
+= sizeof(time
)-1;
674 p
= strchr(locale
, ';');
675 if(locale
[0]=='C' && (locale
[1]==';' || locale
[1]=='\0'))
678 memcpy(buf
, locale
, p
-locale
);
679 lcid
[i
] = MSVCRT_locale_to_LCID(buf
);
681 lcid
[i
] = MSVCRT_locale_to_LCID(locale
);
686 if(!p
|| *(p
+1)!='L' || *(p
+2)!='C' || *(p
+3)!='_')
692 lcid
[0] = MSVCRT_locale_to_LCID(locale
);
702 loc
= MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct
));
706 loc
->locinfo
= MSVCRT_malloc(sizeof(MSVCRT_threadlocinfo
));
712 loc
->mbcinfo
= MSVCRT_malloc(sizeof(MSVCRT_threadmbcinfo
));
714 MSVCRT_free(loc
->locinfo
);
719 memset(loc
->locinfo
, 0, sizeof(MSVCRT_threadlocinfo
));
720 memset(loc
->mbcinfo
, 0, sizeof(MSVCRT_threadmbcinfo
));
722 loc
->locinfo
->lconv
= MSVCRT_malloc(sizeof(struct MSVCRT_lconv
));
723 if(!loc
->locinfo
->lconv
) {
724 MSVCRT__free_locale(loc
);
727 memset(loc
->locinfo
->lconv
, 0, sizeof(struct MSVCRT_lconv
));
729 loc
->locinfo
->pclmap
= MSVCRT_malloc(sizeof(char[256]));
730 loc
->locinfo
->pcumap
= MSVCRT_malloc(sizeof(char[256]));
731 if(!loc
->locinfo
->pclmap
|| !loc
->locinfo
->pcumap
) {
732 MSVCRT__free_locale(loc
);
736 loc
->locinfo
->refcount
= 1;
738 if(lcid
[MSVCRT_LC_COLLATE
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_COLLATE
)) {
739 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_COLLATE
], loc
, MSVCRT_LC_COLLATE
)) {
740 MSVCRT__free_locale(loc
);
744 loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
= _strdup("C");
746 if(lcid
[MSVCRT_LC_CTYPE
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_CTYPE
)) {
749 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_CTYPE
], loc
, MSVCRT_LC_CTYPE
)) {
750 MSVCRT__free_locale(loc
);
754 loc
->locinfo
->lc_codepage
= loc
->locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
;
755 loc
->locinfo
->lc_collate_cp
= loc
->locinfo
->lc_codepage
;
756 loc
->locinfo
->lc_clike
= 1;
757 if(!GetCPInfo(loc
->locinfo
->lc_codepage
, &cp
)) {
758 MSVCRT__free_locale(loc
);
761 loc
->locinfo
->mb_cur_max
= cp
.MaxCharSize
;
763 loc
->locinfo
->ctype1_refcount
= MSVCRT_malloc(sizeof(int));
764 loc
->locinfo
->ctype1
= MSVCRT_malloc(sizeof(short[257]));
765 if(!loc
->locinfo
->ctype1_refcount
|| !loc
->locinfo
->ctype1
) {
766 MSVCRT__free_locale(loc
);
770 *loc
->locinfo
->ctype1_refcount
= 1;
771 loc
->locinfo
->ctype1
[0] = 0;
772 loc
->locinfo
->pctype
= loc
->locinfo
->ctype1
+1;
774 buf
[1] = buf
[2] = '\0';
775 for(i
=1; i
<257; i
++) {
778 GetStringTypeA(lcid
[MSVCRT_LC_CTYPE
], CT_CTYPE1
, buf
,
779 1, loc
->locinfo
->ctype1
+i
);
780 loc
->locinfo
->ctype1
[i
] |= 0x200;
783 loc
->locinfo
->lc_clike
= 1;
784 loc
->locinfo
->mb_cur_max
= 1;
785 loc
->locinfo
->pctype
= MSVCRT__ctype
+1;
786 loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
= _strdup("C");
792 LCMapStringA(lcid
[MSVCRT_LC_CTYPE
], LCMAP_LOWERCASE
, buf
, 256,
793 (char*)loc
->locinfo
->pclmap
, 256);
794 LCMapStringA(lcid
[MSVCRT_LC_CTYPE
], LCMAP_UPPERCASE
, buf
, 256,
795 (char*)loc
->locinfo
->pcumap
, 256);
797 loc
->mbcinfo
->refcount
= 1;
798 loc
->mbcinfo
->mbcodepage
= loc
->locinfo
->lc_id
[MSVCRT_LC_CTYPE
].wCodePage
;
800 for(i
=0; i
<256; i
++) {
801 if(loc
->locinfo
->pclmap
[i
] != i
) {
802 loc
->mbcinfo
->mbctype
[i
+1] |= 0x10;
803 loc
->mbcinfo
->mbcasemap
[i
] = loc
->locinfo
->pclmap
[i
];
804 } else if(loc
->locinfo
->pcumap
[i
] != i
) {
805 loc
->mbcinfo
->mbctype
[i
+1] |= 0x20;
806 loc
->mbcinfo
->mbcasemap
[i
] = loc
->locinfo
->pcumap
[i
];
810 if(lcid
[MSVCRT_LC_MONETARY
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_MONETARY
)) {
811 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_MONETARY
], loc
, MSVCRT_LC_MONETARY
)) {
812 MSVCRT__free_locale(loc
);
816 loc
->locinfo
->lconv_intl_refcount
= MSVCRT_malloc(sizeof(int));
817 loc
->locinfo
->lconv_mon_refcount
= MSVCRT_malloc(sizeof(int));
818 if(!loc
->locinfo
->lconv_intl_refcount
|| !loc
->locinfo
->lconv_mon_refcount
) {
819 MSVCRT__free_locale(loc
);
823 *loc
->locinfo
->lconv_intl_refcount
= 1;
824 *loc
->locinfo
->lconv_mon_refcount
= 1;
826 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SINTLSYMBOL
827 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
828 if(i
&& (loc
->locinfo
->lconv
->int_curr_symbol
= MSVCRT_malloc(sizeof(char[i
]))))
829 memcpy(loc
->locinfo
->lconv
->int_curr_symbol
, buf
, sizeof(char[i
]));
831 MSVCRT__free_locale(loc
);
835 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SCURRENCY
836 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
837 if(i
&& (loc
->locinfo
->lconv
->currency_symbol
= MSVCRT_malloc(sizeof(char[i
]))))
838 memcpy(loc
->locinfo
->lconv
->currency_symbol
, buf
, sizeof(char[i
]));
840 MSVCRT__free_locale(loc
);
844 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONDECIMALSEP
845 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
846 if(i
&& (loc
->locinfo
->lconv
->mon_decimal_point
= MSVCRT_malloc(sizeof(char[i
]))))
847 memcpy(loc
->locinfo
->lconv
->mon_decimal_point
, buf
, sizeof(char[i
]));
849 MSVCRT__free_locale(loc
);
853 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONTHOUSANDSEP
854 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
855 if(i
&& (loc
->locinfo
->lconv
->mon_thousands_sep
= MSVCRT_malloc(sizeof(char[i
]))))
856 memcpy(loc
->locinfo
->lconv
->mon_thousands_sep
, buf
, sizeof(char[i
]));
858 MSVCRT__free_locale(loc
);
862 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SMONGROUPING
863 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
865 i
= i
/2 + (buf
[i
-2]=='0'?0:1);
866 if(i
&& (loc
->locinfo
->lconv
->mon_grouping
= MSVCRT_malloc(sizeof(char[i
])))) {
867 for(i
=0; buf
[i
+1]==';'; i
+=2)
868 loc
->locinfo
->lconv
->mon_grouping
[i
/2] = buf
[i
]-'0';
869 loc
->locinfo
->lconv
->mon_grouping
[i
/2] = buf
[i
]-'0';
871 loc
->locinfo
->lconv
->mon_grouping
[i
/2+1] = 127;
873 MSVCRT__free_locale(loc
);
877 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SPOSITIVESIGN
878 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
879 if(i
&& (loc
->locinfo
->lconv
->positive_sign
= MSVCRT_malloc(sizeof(char[i
]))))
880 memcpy(loc
->locinfo
->lconv
->positive_sign
, buf
, sizeof(char[i
]));
882 MSVCRT__free_locale(loc
);
886 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_SNEGATIVESIGN
887 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
888 if(i
&& (loc
->locinfo
->lconv
->negative_sign
= MSVCRT_malloc(sizeof(char[i
]))))
889 memcpy(loc
->locinfo
->lconv
->negative_sign
, buf
, sizeof(char[i
]));
891 MSVCRT__free_locale(loc
);
895 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IINTLCURRDIGITS
896 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
897 loc
->locinfo
->lconv
->int_frac_digits
= atoi(buf
);
899 MSVCRT__free_locale(loc
);
903 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_ICURRDIGITS
904 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
905 loc
->locinfo
->lconv
->frac_digits
= atoi(buf
);
907 MSVCRT__free_locale(loc
);
911 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSYMPRECEDES
912 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
913 loc
->locinfo
->lconv
->p_cs_precedes
= atoi(buf
);
915 MSVCRT__free_locale(loc
);
919 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSEPBYSPACE
920 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
921 loc
->locinfo
->lconv
->p_sep_by_space
= atoi(buf
);
923 MSVCRT__free_locale(loc
);
927 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSYMPRECEDES
928 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
929 loc
->locinfo
->lconv
->n_cs_precedes
= atoi(buf
);
931 MSVCRT__free_locale(loc
);
935 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSEPBYSPACE
936 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
937 loc
->locinfo
->lconv
->n_sep_by_space
= atoi(buf
);
939 MSVCRT__free_locale(loc
);
943 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_IPOSSIGNPOSN
944 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
945 loc
->locinfo
->lconv
->p_sign_posn
= atoi(buf
);
947 MSVCRT__free_locale(loc
);
951 if(GetLocaleInfoA(lcid
[MSVCRT_LC_MONETARY
], LOCALE_INEGSIGNPOSN
952 |LOCALE_NOUSEROVERRIDE
, buf
, 256))
953 loc
->locinfo
->lconv
->n_sign_posn
= atoi(buf
);
955 MSVCRT__free_locale(loc
);
959 loc
->locinfo
->lconv
->int_curr_symbol
= MSVCRT_malloc(sizeof(char));
960 loc
->locinfo
->lconv
->currency_symbol
= MSVCRT_malloc(sizeof(char));
961 loc
->locinfo
->lconv
->mon_decimal_point
= MSVCRT_malloc(sizeof(char));
962 loc
->locinfo
->lconv
->mon_thousands_sep
= MSVCRT_malloc(sizeof(char));
963 loc
->locinfo
->lconv
->mon_grouping
= MSVCRT_malloc(sizeof(char));
964 loc
->locinfo
->lconv
->positive_sign
= MSVCRT_malloc(sizeof(char));
965 loc
->locinfo
->lconv
->negative_sign
= MSVCRT_malloc(sizeof(char));
967 if(!loc
->locinfo
->lconv
->int_curr_symbol
|| !loc
->locinfo
->lconv
->currency_symbol
968 || !loc
->locinfo
->lconv
->mon_decimal_point
|| !loc
->locinfo
->lconv
->mon_thousands_sep
969 || !loc
->locinfo
->lconv
->mon_grouping
|| !loc
->locinfo
->lconv
->positive_sign
970 || !loc
->locinfo
->lconv
->negative_sign
) {
971 MSVCRT__free_locale(loc
);
975 loc
->locinfo
->lconv
->int_curr_symbol
[0] = '\0';
976 loc
->locinfo
->lconv
->currency_symbol
[0] = '\0';
977 loc
->locinfo
->lconv
->mon_decimal_point
[0] = '\0';
978 loc
->locinfo
->lconv
->mon_thousands_sep
[0] = '\0';
979 loc
->locinfo
->lconv
->mon_grouping
[0] = '\0';
980 loc
->locinfo
->lconv
->positive_sign
[0] = '\0';
981 loc
->locinfo
->lconv
->negative_sign
[0] = '\0';
982 loc
->locinfo
->lconv
->int_frac_digits
= 127;
983 loc
->locinfo
->lconv
->frac_digits
= 127;
984 loc
->locinfo
->lconv
->p_cs_precedes
= 127;
985 loc
->locinfo
->lconv
->p_sep_by_space
= 127;
986 loc
->locinfo
->lconv
->n_cs_precedes
= 127;
987 loc
->locinfo
->lconv
->n_sep_by_space
= 127;
988 loc
->locinfo
->lconv
->p_sign_posn
= 127;
989 loc
->locinfo
->lconv
->n_sign_posn
= 127;
991 loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
= _strdup("C");
994 if(lcid
[MSVCRT_LC_NUMERIC
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_NUMERIC
)) {
995 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_NUMERIC
], loc
, MSVCRT_LC_NUMERIC
)) {
996 MSVCRT__free_locale(loc
);
1000 if(!loc
->locinfo
->lconv_intl_refcount
)
1001 loc
->locinfo
->lconv_intl_refcount
= MSVCRT_malloc(sizeof(int));
1002 loc
->locinfo
->lconv_num_refcount
= MSVCRT_malloc(sizeof(int));
1003 if(!loc
->locinfo
->lconv_intl_refcount
|| !loc
->locinfo
->lconv_num_refcount
) {
1004 MSVCRT__free_locale(loc
);
1008 *loc
->locinfo
->lconv_intl_refcount
= 1;
1009 *loc
->locinfo
->lconv_num_refcount
= 1;
1011 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SDECIMAL
1012 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1013 if(i
&& (loc
->locinfo
->lconv
->decimal_point
= MSVCRT_malloc(sizeof(char[i
]))))
1014 memcpy(loc
->locinfo
->lconv
->decimal_point
, buf
, sizeof(char[i
]));
1016 MSVCRT__free_locale(loc
);
1020 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_STHOUSAND
1021 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1022 if(i
&& (loc
->locinfo
->lconv
->thousands_sep
= MSVCRT_malloc(sizeof(char[i
]))))
1023 memcpy(loc
->locinfo
->lconv
->thousands_sep
, buf
, sizeof(char[i
]));
1025 MSVCRT__free_locale(loc
);
1029 i
= GetLocaleInfoA(lcid
[MSVCRT_LC_NUMERIC
], LOCALE_SGROUPING
1030 |LOCALE_NOUSEROVERRIDE
, buf
, 256);
1032 i
= i
/2 + (buf
[i
-2]=='0'?0:1);
1033 if(i
&& (loc
->locinfo
->lconv
->grouping
= MSVCRT_malloc(sizeof(char[i
])))) {
1034 for(i
=0; buf
[i
+1]==';'; i
+=2)
1035 loc
->locinfo
->lconv
->grouping
[i
/2] = buf
[i
]-'0';
1036 loc
->locinfo
->lconv
->grouping
[i
/2] = buf
[i
]-'0';
1038 loc
->locinfo
->lconv
->grouping
[i
/2+1] = 127;
1040 MSVCRT__free_locale(loc
);
1044 loc
->locinfo
->lconv
->decimal_point
= MSVCRT_malloc(sizeof(char[2]));
1045 loc
->locinfo
->lconv
->thousands_sep
= MSVCRT_malloc(sizeof(char));
1046 loc
->locinfo
->lconv
->grouping
= MSVCRT_malloc(sizeof(char));
1047 if(!loc
->locinfo
->lconv
->decimal_point
|| !loc
->locinfo
->lconv
->thousands_sep
1048 || !loc
->locinfo
->lconv
->grouping
) {
1049 MSVCRT__free_locale(loc
);
1053 loc
->locinfo
->lconv
->decimal_point
[0] = '.';
1054 loc
->locinfo
->lconv
->decimal_point
[1] = '\0';
1055 loc
->locinfo
->lconv
->thousands_sep
[0] = '\0';
1056 loc
->locinfo
->lconv
->grouping
[0] = '\0';
1058 loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
= _strdup("C");
1061 if(lcid
[MSVCRT_LC_TIME
] && (category
==MSVCRT_LC_ALL
|| category
==MSVCRT_LC_TIME
)) {
1062 if(update_threadlocinfo_category(lcid
[MSVCRT_LC_TIME
], loc
, MSVCRT_LC_TIME
)) {
1063 MSVCRT__free_locale(loc
);
1067 loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
= _strdup("C");
1072 /* _configthreadlocale - not exported in native msvcrt */
1073 int CDECL
_configthreadlocale(int type
)
1075 thread_data_t
*data
= msvcrt_get_thread_data();
1081 ret
= (data
->locale
? MSVCRT__ENABLE_PER_THREAD_LOCALE
: MSVCRT__DISABLE_PER_THREAD_LOCALE
);
1083 if(type
== MSVCRT__ENABLE_PER_THREAD_LOCALE
) {
1085 /* Copy current global locale */
1086 data
->locale
= MSVCRT__create_locale(MSVCRT_LC_ALL
, MSVCRT_setlocale(MSVCRT_LC_ALL
, NULL
));
1094 if(type
== MSVCRT__DISABLE_PER_THREAD_LOCALE
) {
1096 MSVCRT__free_locale(data
->locale
);
1097 data
->locale
= NULL
;
1109 /*********************************************************************
1110 * setlocale (MSVCRT.@)
1112 char* CDECL
MSVCRT_setlocale(int category
, const char* locale
)
1114 MSVCRT__locale_t loc
, cur
;
1118 if(category
<MSVCRT_LC_MIN
|| category
>MSVCRT_LC_MAX
)
1122 if(category
== MSVCRT_LC_ALL
)
1123 return construct_lc_all(cur
);
1125 return cur
->locinfo
->lc_category
[category
].locale
;
1128 loc
= MSVCRT__create_locale(category
, locale
);
1130 WARN("%d %s failed\n", category
, locale
);
1140 case MSVCRT_LC_COLLATE
:
1141 cur
->locinfo
->lc_handle
[MSVCRT_LC_COLLATE
] =
1142 loc
->locinfo
->lc_handle
[MSVCRT_LC_COLLATE
];
1143 swap_pointers((void**)&cur
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
,
1144 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].locale
);
1145 swap_pointers((void**)&cur
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].refcount
,
1146 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_COLLATE
].refcount
);
1148 if(category
!= MSVCRT_LC_ALL
)
1150 case MSVCRT_LC_CTYPE
:
1151 cur
->locinfo
->lc_handle
[MSVCRT_LC_CTYPE
] =
1152 loc
->locinfo
->lc_handle
[MSVCRT_LC_CTYPE
];
1153 swap_pointers((void**)&cur
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
,
1154 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].locale
);
1155 swap_pointers((void**)&cur
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].refcount
,
1156 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_CTYPE
].refcount
);
1158 cur
->locinfo
->lc_codepage
= loc
->locinfo
->lc_codepage
;
1159 cur
->locinfo
->lc_collate_cp
= loc
->locinfo
->lc_collate_cp
;
1160 cur
->locinfo
->lc_clike
= loc
->locinfo
->lc_clike
;
1161 cur
->locinfo
->mb_cur_max
= loc
->locinfo
->mb_cur_max
;
1163 swap_pointers((void**)&cur
->locinfo
->ctype1_refcount
,
1164 (void**)&loc
->locinfo
->ctype1_refcount
);
1165 swap_pointers((void**)&cur
->locinfo
->ctype1
, (void**)&loc
->locinfo
->ctype1
);
1166 swap_pointers((void**)&cur
->locinfo
->pctype
, (void**)&loc
->locinfo
->pctype
);
1167 swap_pointers((void**)&cur
->locinfo
->pclmap
, (void**)&loc
->locinfo
->pclmap
);
1168 swap_pointers((void**)&cur
->locinfo
->pcumap
, (void**)&loc
->locinfo
->pcumap
);
1170 memcpy(cur
->mbcinfo
, loc
->mbcinfo
, sizeof(MSVCRT_threadmbcinfo
));
1172 if(category
!= MSVCRT_LC_ALL
)
1174 case MSVCRT_LC_MONETARY
:
1175 cur
->locinfo
->lc_handle
[MSVCRT_LC_MONETARY
] =
1176 loc
->locinfo
->lc_handle
[MSVCRT_LC_MONETARY
];
1177 swap_pointers((void**)&cur
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
,
1178 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].locale
);
1179 swap_pointers((void**)&cur
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].refcount
,
1180 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_MONETARY
].refcount
);
1182 swap_pointers((void**)&cur
->locinfo
->lconv
->int_curr_symbol
,
1183 (void**)&loc
->locinfo
->lconv
->int_curr_symbol
);
1184 swap_pointers((void**)&cur
->locinfo
->lconv
->currency_symbol
,
1185 (void**)&loc
->locinfo
->lconv
->currency_symbol
);
1186 swap_pointers((void**)&cur
->locinfo
->lconv
->mon_decimal_point
,
1187 (void**)&loc
->locinfo
->lconv
->mon_decimal_point
);
1188 swap_pointers((void**)&cur
->locinfo
->lconv
->mon_thousands_sep
,
1189 (void**)&loc
->locinfo
->lconv
->mon_thousands_sep
);
1190 swap_pointers((void**)&cur
->locinfo
->lconv
->mon_grouping
,
1191 (void**)&loc
->locinfo
->lconv
->mon_grouping
);
1192 swap_pointers((void**)&cur
->locinfo
->lconv
->positive_sign
,
1193 (void**)&loc
->locinfo
->lconv
->positive_sign
);
1194 swap_pointers((void**)&cur
->locinfo
->lconv
->negative_sign
,
1195 (void**)&loc
->locinfo
->lconv
->negative_sign
);
1196 cur
->locinfo
->lconv
->int_frac_digits
= loc
->locinfo
->lconv
->int_frac_digits
;
1197 cur
->locinfo
->lconv
->frac_digits
= loc
->locinfo
->lconv
->frac_digits
;
1198 cur
->locinfo
->lconv
->p_cs_precedes
= loc
->locinfo
->lconv
->p_cs_precedes
;
1199 cur
->locinfo
->lconv
->p_sep_by_space
= loc
->locinfo
->lconv
->p_sep_by_space
;
1200 cur
->locinfo
->lconv
->n_cs_precedes
= loc
->locinfo
->lconv
->n_cs_precedes
;
1201 cur
->locinfo
->lconv
->n_sep_by_space
= loc
->locinfo
->lconv
->n_sep_by_space
;
1202 cur
->locinfo
->lconv
->p_sign_posn
= loc
->locinfo
->lconv
->p_sign_posn
;
1203 cur
->locinfo
->lconv
->n_sign_posn
= loc
->locinfo
->lconv
->n_sign_posn
;
1205 if(category
!= MSVCRT_LC_ALL
)
1207 case MSVCRT_LC_NUMERIC
:
1208 cur
->locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
] =
1209 loc
->locinfo
->lc_handle
[MSVCRT_LC_NUMERIC
];
1210 swap_pointers((void**)&cur
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
,
1211 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].locale
);
1212 swap_pointers((void**)&cur
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].refcount
,
1213 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_NUMERIC
].refcount
);
1215 swap_pointers((void**)&cur
->locinfo
->lconv
->decimal_point
,
1216 (void**)&loc
->locinfo
->lconv
->decimal_point
);
1217 swap_pointers((void**)&cur
->locinfo
->lconv
->thousands_sep
,
1218 (void**)&loc
->locinfo
->lconv
->thousands_sep
);
1219 swap_pointers((void**)&cur
->locinfo
->lconv
->grouping
,
1220 (void**)&loc
->locinfo
->lconv
->grouping
);
1222 if(category
!= MSVCRT_LC_ALL
)
1224 case MSVCRT_LC_TIME
:
1225 cur
->locinfo
->lc_handle
[MSVCRT_LC_TIME
] =
1226 loc
->locinfo
->lc_handle
[MSVCRT_LC_TIME
];
1227 swap_pointers((void**)&cur
->locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
,
1228 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].locale
);
1229 swap_pointers((void**)&cur
->locinfo
->lc_category
[MSVCRT_LC_TIME
].refcount
,
1230 (void**)&loc
->locinfo
->lc_category
[MSVCRT_LC_TIME
].refcount
);
1232 if(category
!= MSVCRT_LC_ALL
)
1237 MSVCRT_locale
= cur
= loc
;
1239 MSVCRT__free_locale(loc
);
1243 if(cur
== MSVCRT_locale
) {
1244 MSVCRT___lc_codepage
= cur
->locinfo
->lc_codepage
;
1245 MSVCRT___lc_collate_cp
= cur
->locinfo
->lc_collate_cp
;
1246 MSVCRT___mb_cur_max
= cur
->locinfo
->mb_cur_max
;
1247 MSVCRT__pctype
= cur
->locinfo
->pctype
;
1250 if(category
== MSVCRT_LC_ALL
)
1251 return construct_lc_all(cur
);
1253 return cur
->locinfo
->lc_category
[category
].locale
;