ReactOS 0.4.16-dev-319-g6cf4263
locale.h File Reference
#include <crtdefs.h>
Include dependency graph for locale.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MSVCRT_threadlocaleinfostruct
 
struct  MSVCRT_threadmbcinfostruct
 
struct  MSVCRT_localeinfo_struct
 
struct  __lc_time_data
 

Macros

#define MSVCRT_lconv   lconv
 
#define MSVCRT_locale   __get_MSVCRT_locale()
 

Typedefs

typedef struct MSVCRT_threadlocaleinfostruct MSVCRT_threadlocinfo
 
typedef struct MSVCRT_threadmbcinfostruct MSVCRT_threadmbcinfo
 
typedef struct MSVCRT_threadlocaleinfostructMSVCRT_pthreadlocinfo
 
typedef struct MSVCRT_threadmbcinfostructMSVCRT_pthreadmbcinfo
 
typedef struct MSVCRT_localeinfo_struct MSVCRT__locale_tstruct
 
typedef struct MSVCRT_localeinfo_structMSVCRT__locale_t
 
typedef struct __lc_time_data MSVCRT___lc_time_data
 

Functions

int _setmbcp_l (int, LCID, MSVCRT_pthreadmbcinfo) DECLSPEC_HIDDEN
 
MSVCRT_pthreadmbcinfo get_mbcinfo (void) DECLSPEC_HIDDEN
 
LCID MSVCRT_locale_to_LCID (const char *, unsigned short *) DECLSPEC_HIDDEN
 
void __init_global_locale ()
 
FORCEINLINE MSVCRT__locale_t __get_MSVCRT_locale ()
 
MSVCRT_pthreadlocinfo get_locinfo (void)
 
void __cdecl MSVCRT__free_locale (MSVCRT__locale_t)
 
void free_locinfo (MSVCRT_pthreadlocinfo)
 
void free_mbcinfo (MSVCRT_pthreadmbcinfo)
 

Variables

MSVCRT__locale_t global_locale
 

Macro Definition Documentation

◆ MSVCRT_lconv

Definition at line 42 of file locale.h.

◆ MSVCRT_locale

Typedef Documentation

◆ MSVCRT___lc_time_data

◆ MSVCRT__locale_t

◆ MSVCRT__locale_tstruct

◆ MSVCRT_pthreadlocinfo

◆ MSVCRT_pthreadmbcinfo

Definition at line 45 of file locale.h.

◆ MSVCRT_threadlocinfo

◆ MSVCRT_threadmbcinfo

Function Documentation

◆ __get_MSVCRT_locale()

FORCEINLINE MSVCRT__locale_t __get_MSVCRT_locale ( )

Definition at line 81 of file locale.h.

82{
83 if(!global_locale)
85 return global_locale;
86}
MSVCRT__locale_t global_locale
Definition: locale.c:1497
void __init_global_locale()
Definition: locale.c:1498

◆ __init_global_locale()

void __init_global_locale ( )

Definition at line 1498 of file locale.c.

1499{
1500 unsigned i;
1501
1503 /* Someone created it before us */
1504 if(global_locale)
1505 return;
1507
1508 __lc_codepage = MSVCRT_locale->locinfo->lc_codepage;
1509 MSVCRT___lc_collate_cp = MSVCRT_locale->locinfo->lc_collate_cp;
1510 __mb_cur_max = MSVCRT_locale->locinfo->mb_cur_max;
1511 for(i=LC_MIN; i<=LC_MAX; i++)
1512 MSVCRT___lc_handle[i] = MSVCRT_locale->locinfo->lc_handle[i];
1515}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define LC_MAX
Definition: locale.h:25
#define LC_MIN
Definition: locale.h:24
#define MSVCRT_locale
Definition: locale.h:80
int __cdecl _setmbcp(int)
Definition: _setmbcp.c:218
#define _MB_CP_ANSI
Definition: msvcrt.h:830
int MSVCRT___lc_collate_cp
Definition: locale.c:37
#define LOCK_LOCALE
Definition: locale.c:45
MSVCRT__locale_t global_locale
Definition: locale.c:1497
int __mb_cur_max
Definition: locale.c:39
#define UNLOCK_LOCALE
Definition: locale.c:46
LCID MSVCRT___lc_handle[LC_MAX - LC_MIN+1]
Definition: locale.c:38
unsigned int __lc_codepage
Definition: locale.c:36
MSVCRT__locale_t CDECL MSVCRT__create_locale(int category, const char *locale)
Definition: locale.c:724

Referenced by __get_MSVCRT_locale().

◆ _setmbcp_l()

int _setmbcp_l ( int  cp,
LCID  lcid,
MSVCRT_pthreadmbcinfo  mbcinfo 
)

Definition at line 52 of file _setmbcp.c.

53{
54 const char format[] = ".%d";
55
56 int newcp;
57 CPINFO cpi;
58 BYTE *bytes;
59 WORD chartypes[256];
60 char bufA[256];
61 WCHAR bufW[256];
62 int charcount;
63 int ret;
64 int i;
65
66 if(!mbcinfo)
67 mbcinfo = get_mbcinfo();
68
69 switch (cp)
70 {
71 case _MB_CP_ANSI:
72 newcp = GetACP();
73 break;
74 case _MB_CP_OEM:
75 newcp = GetOEMCP();
76 break;
77 case _MB_CP_LOCALE:
78 newcp = get_locinfo()->lc_codepage;
79 if(newcp)
80 break;
81 /* fall through (C locale) */
82 case _MB_CP_SBCS:
83 newcp = 20127; /* ASCII */
84 break;
85 default:
86 newcp = cp;
87 break;
88 }
89
90 if(lcid == -1) {
91 sprintf(bufA, format, newcp);
92 mbcinfo->mblcid = MSVCRT_locale_to_LCID(bufA, NULL);
93 } else {
94 mbcinfo->mblcid = lcid;
95 }
96
97 if(mbcinfo->mblcid == -1)
98 {
99 WARN("Can't assign LCID to codepage (%d)\n", mbcinfo->mblcid);
100 mbcinfo->mblcid = 0;
101 }
102
103 if (!GetCPInfo(newcp, &cpi))
104 {
105 WARN("Codepage %d not found\n", newcp);
106 *_errno() = EINVAL;
107 return -1;
108 }
109
110 /* setup the _mbctype */
111 memset(mbcinfo->mbctype, 0, sizeof(unsigned char[257]));
112 memset(mbcinfo->mbcasemap, 0, sizeof(unsigned char[256]));
113
114 bytes = cpi.LeadByte;
115 while (bytes[0] || bytes[1])
116 {
117 for (i = bytes[0]; i <= bytes[1]; i++)
118 mbcinfo->mbctype[i + 1] |= _M1;
119 bytes += 2;
120 }
121
122 if (cpi.MaxCharSize > 1)
123 {
124 /* trail bytes not available through kernel32 but stored in a structure in msvcrt */
125 struct cp_extra_info_t *cpextra = g_cpextrainfo;
126
127 mbcinfo->ismbcodepage = 1;
128 while (TRUE)
129 {
130 if (cpextra->cp == 0 || cpextra->cp == newcp)
131 {
132 if (cpextra->cp == 0)
133 FIXME("trail bytes data not available for DBCS codepage %d - assuming all bytes\n", newcp);
134
135 bytes = cpextra->TrailBytes;
136 while (bytes[0] || bytes[1])
137 {
138 for (i = bytes[0]; i <= bytes[1]; i++)
139 mbcinfo->mbctype[i + 1] |= _M2;
140 bytes += 2;
141 }
142 break;
143 }
144 cpextra++;
145 }
146 }
147 else
148 mbcinfo->ismbcodepage = 0;
149
150 /* we can't use GetStringTypeA directly because we don't have a locale - only a code page
151 */
152 charcount = 0;
153 for (i = 0; i < 256; i++)
154 if (!(mbcinfo->mbctype[i + 1] & _M1))
155 bufA[charcount++] = i;
156
157 ret = MultiByteToWideChar(newcp, 0, bufA, charcount, bufW, charcount);
158 if (ret != charcount)
159 ERR("MultiByteToWideChar of chars failed for cp %d, ret=%d (exp %d), error=%d\n", newcp, ret, charcount, GetLastError());
160
161 GetStringTypeW(CT_CTYPE1, bufW, charcount, chartypes);
162
163 charcount = 0;
164 for (i = 0; i < 256; i++)
165 if (!(mbcinfo->mbctype[i + 1] & _M1))
166 {
167 if (chartypes[charcount] & C1_UPPER)
168 {
169 mbcinfo->mbctype[i + 1] |= _SBUP;
170 bufW[charcount] = tolowerW(bufW[charcount]);
171 }
172 else if (chartypes[charcount] & C1_LOWER)
173 {
174 mbcinfo->mbctype[i + 1] |= _SBLOW;
175 bufW[charcount] = toupperW(bufW[charcount]);
176 }
177 charcount++;
178 }
179
180 ret = WideCharToMultiByte(newcp, 0, bufW, charcount, bufA, charcount, NULL, NULL);
181 if (ret != charcount)
182 ERR("WideCharToMultiByte failed for cp %d, ret=%d (exp %d), error=%d\n", newcp, ret, charcount, GetLastError());
183
184 charcount = 0;
185 for (i = 0; i < 256; i++)
186 {
187 if(!(mbcinfo->mbctype[i + 1] & _M1))
188 {
189 if(mbcinfo->mbctype[i] & (C1_UPPER|C1_LOWER))
190 mbcinfo->mbcasemap[i] = bufA[charcount];
191 charcount++;
192 }
193 }
194
195 if (newcp == 932) /* CP932 only - set _MP and _MS */
196 {
197 /* On Windows it's possible to calculate the _MP and _MS from CT_CTYPE1
198 * and CT_CTYPE3. But as of Wine 0.9.43 we return wrong values what makes
199 * it hard. As this is set only for codepage 932 we hardcode it what gives
200 * also faster execution.
201 */
202 for (i = 161; i <= 165; i++)
203 mbcinfo->mbctype[i + 1] |= _MP;
204 for (i = 166; i <= 223; i++)
205 mbcinfo->mbctype[i + 1] |= _MS;
206 }
207
208 mbcinfo->mbcodepage = newcp;
209 if(global_locale && mbcinfo == MSVCRT_locale->mbcinfo)
210 memcpy(_mbctype, MSVCRT_locale->mbcinfo->mbctype, sizeof(_mbctype));
211
212 return 0;
213}
static struct cp_extra_info_t g_cpextrainfo[]
Definition: _setmbcp.c:38
#define EINVAL
Definition: acclib.h:90
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define WideCharToMultiByte
Definition: compat.h:111
#define MultiByteToWideChar
Definition: compat.h:110
UINT WINAPI GetACP(void)
Definition: locale.c:2021
BOOL WINAPI GetCPInfo(UINT codepage, LPCPINFO cpinfo)
Definition: locale.c:2144
BOOL WINAPI GetStringTypeW(DWORD type, LPCWSTR src, INT count, LPWORD chartype)
Definition: locale.c:3095
UINT WINAPI GetOEMCP(void)
Definition: locale.c:2060
unsigned short WORD
Definition: ntddk_ex.h:93
#define C1_LOWER
Definition: unicode.h:32
#define C1_UPPER
Definition: unicode.h:31
POINT cp
Definition: magnifier.c:59
_CRTIMP unsigned char _mbctype[257]
Definition: locale.c:42
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define for
Definition: utility.h:88
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define _M2
Definition: msvcrt.h:818
LCID MSVCRT_locale_to_LCID(const char *)
MSVCRT_pthreadmbcinfo get_mbcinfo(void)
Definition: locale.c:366
#define _MP
Definition: msvcrt.h:816
#define _MB_CP_OEM
Definition: msvcrt.h:829
#define _MB_CP_LOCALE
Definition: msvcrt.h:831
#define _M1
Definition: msvcrt.h:817
#define _SBLOW
Definition: msvcrt.h:821
#define _SBUP
Definition: msvcrt.h:820
#define _MS
Definition: msvcrt.h:815
#define _MB_CP_SBCS
Definition: msvcrt.h:828
#define toupperW(n)
Definition: unicode.h:51
#define tolowerW(n)
Definition: unicode.h:50
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:17
#define memset(x, y, z)
Definition: compat.h:39
unsigned char mbcasemap[256]
Definition: msvcrt.h:144
unsigned char mbctype[257]
Definition: msvcrt.h:143
BYTE LeadByte[MAX_LEADBYTES]
Definition: winnls.h:585
UINT MaxCharSize
Definition: winnls.h:583
BYTE TrailBytes[MAX_LEADBYTES]
Definition: _setmbcp.c:35
Definition: format.c:58
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define get_locinfo()
Definition: winesup.h:25
#define CT_CTYPE1
Definition: winnls.h:239
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193

Referenced by _setmbcp().

◆ free_locinfo()

void free_locinfo ( MSVCRT_pthreadlocinfo  locinfo)

Definition at line 643 of file locale.c.

644{
645 int i;
646
647 if(!locinfo)
648 return;
649
650 if(InterlockedDecrement(&locinfo->refcount))
651 return;
652
653 for(i=MSVCRT_LC_MIN+1; i<=MSVCRT_LC_MAX; i++) {
654 MSVCRT_free(locinfo->lc_category[i].locale);
655 MSVCRT_free(locinfo->lc_category[i].refcount);
656 }
657
658 if(locinfo->lconv) {
659 MSVCRT_free(locinfo->lconv->decimal_point);
660 MSVCRT_free(locinfo->lconv->thousands_sep);
661 MSVCRT_free(locinfo->lconv->grouping);
662 MSVCRT_free(locinfo->lconv->int_curr_symbol);
663 MSVCRT_free(locinfo->lconv->currency_symbol);
664 MSVCRT_free(locinfo->lconv->mon_decimal_point);
665 MSVCRT_free(locinfo->lconv->mon_thousands_sep);
666 MSVCRT_free(locinfo->lconv->mon_grouping);
667 MSVCRT_free(locinfo->lconv->positive_sign);
668 MSVCRT_free(locinfo->lconv->negative_sign);
669 }
670 MSVCRT_free(locinfo->lconv_intl_refcount);
671 MSVCRT_free(locinfo->lconv_num_refcount);
672 MSVCRT_free(locinfo->lconv_mon_refcount);
673 MSVCRT_free(locinfo->lconv);
674
675 MSVCRT_free(locinfo->ctype1_refcount);
676 MSVCRT_free(locinfo->ctype1);
677
678 MSVCRT_free(locinfo->pclmap);
679 MSVCRT_free(locinfo->pcumap);
680
681 MSVCRT_free(locinfo->lc_time_curr);
682
684}
#define InterlockedDecrement
Definition: armddk.h:52
#define MSVCRT_LC_MAX
Definition: msvcrt.h:657
#define MSVCRT_LC_MIN
Definition: msvcrt.h:656
else locinfo
Definition: scanf.h:159
#define MSVCRT_free
Definition: msvcrt.h:152

Referenced by _configthreadlocale(), and MSVCRT__free_locale().

◆ free_mbcinfo()

void free_mbcinfo ( MSVCRT_pthreadmbcinfo  mbcinfo)

Definition at line 687 of file locale.c.

688{
689 if(!mbcinfo)
690 return;
691
692 if(InterlockedDecrement(&mbcinfo->refcount))
693 return;
694
695 MSVCRT_free(mbcinfo);
696}

Referenced by _configthreadlocale(), and MSVCRT__free_locale().

◆ get_locinfo()

MSVCRT_pthreadlocinfo get_locinfo ( void  )

Definition at line 356 of file locale.c.

356 {
358
359 if(!data || !data->have_locale)
360 return MSVCRT_locale->locinfo;
361
362 return data->locinfo;
363}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
thread_data_t * msvcrt_get_thread_data(void)
Definition: tls.c:31

◆ get_mbcinfo()

MSVCRT_pthreadmbcinfo get_mbcinfo ( void  )

Definition at line 366 of file locale.c.

366 {
368
369 if(!data || !data->have_locale)
370 return MSVCRT_locale->mbcinfo;
371
372 return data->mbcinfo;
373}

◆ MSVCRT__free_locale()

void __cdecl MSVCRT__free_locale ( MSVCRT__locale_t  locale)

Definition at line 713 of file locale.c.

714{
715 if (!locale)
716 return;
717
718 free_locinfo(locale->locinfo);
719 free_mbcinfo(locale->mbcinfo);
721}
Definition: _locale.h:75
void free_locinfo(MSVCRT_pthreadlocinfo locinfo)
Definition: locale.c:643
void free_mbcinfo(MSVCRT_pthreadmbcinfo mbcinfo)
Definition: locale.c:687

Referenced by MSVCRT__create_locale(), and setlocale().

◆ MSVCRT_locale_to_LCID()

LCID MSVCRT_locale_to_LCID ( const char locale,
unsigned short codepage 
)

Definition at line 210 of file locale.c.

211{
212 LCID lcid;
214 const char *cp, *region;
215
216 memset(&search, 0, sizeof(locale_search_t));
217
218 cp = strchr(locale, '.');
219 region = strchr(locale, '_');
220
221 lstrcpynA(search.search_language, locale, MAX_ELEM_LEN);
222 if(region) {
223 lstrcpynA(search.search_country, region+1, MAX_ELEM_LEN);
224 if(region-locale < MAX_ELEM_LEN)
225 search.search_language[region-locale] = '\0';
226 } else
227 search.search_country[0] = '\0';
228
229 if(cp) {
230 lstrcpynA(search.search_codepage, cp+1, MAX_ELEM_LEN);
231 if(region && cp-region-1<MAX_ELEM_LEN)
232 search.search_country[cp-region-1] = '\0';
234 search.search_language[cp-locale] = '\0';
235 } else
236 search.search_codepage[0] = '\0';
237
238 if(!search.search_country[0] && !search.search_codepage[0])
239 remap_synonym(search.search_language);
240
243 (LONG_PTR)&search);
244
245 if (!search.match_flags)
246 return -1;
247
248 /* If we were given something that didn't match, fail */
249 if (search.search_country[0] && !(search.match_flags & FOUND_COUNTRY))
250 return -1;
251
252 lcid = MAKELCID(search.found_lang_id, SORT_DEFAULT);
253
254 /* Populate partial locale, translating LCID to locale string elements */
255 if (!(search.match_flags & FOUND_CODEPAGE)) {
256 /* Even if a codepage is not enumerated for a locale
257 * it can be set if valid */
258 if (search.search_codepage[0]) {
259 if (IsValidCodePage(atoi(search.search_codepage)))
260 memcpy(search.found_codepage,search.search_codepage,MAX_ELEM_LEN);
261 else {
262 /* Special codepage values: OEM & ANSI */
263 if (!strcasecmp(search.search_codepage,"OCP")) {
265 search.found_codepage, MAX_ELEM_LEN);
266 } else if (!strcasecmp(search.search_codepage,"ACP")) {
268 search.found_codepage, MAX_ELEM_LEN);
269 } else
270 return -1;
271
272 if (!atoi(search.found_codepage))
273 return -1;
274 }
275 } else {
276 /* Prefer ANSI codepages if present */
278 search.found_codepage, MAX_ELEM_LEN);
279 if (!search.found_codepage[0] || !atoi(search.found_codepage))
281 search.found_codepage, MAX_ELEM_LEN);
282 }
283 }
284 if (codepage)
285 *codepage = atoi(search.found_codepage);
286
287 return lcid;
288}
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define lstrcpynA
Definition: compat.h:751
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
BOOL WINAPI EnumResourceLanguagesA(HMODULE hmod, LPCSTR type, LPCSTR name, ENUMRESLANGPROCA lpfun, LONG_PTR lparam)
Definition: res.c:428
BOOL WINAPI IsValidCodePage(UINT codepage)
Definition: locale.c:2079
INT WINAPI GetLocaleInfoA(LCID lcid, LCTYPE lctype, LPSTR buffer, INT len)
Definition: locale.c:1600
static short search(int val, const short *table, int size)
Definition: msg711.c:255
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define SORT_DEFAULT
#define MAKELCID(lgid, srtid)
#define RT_STRING
Definition: pedump.c:368
DWORD LCID
Definition: nls.h:13
static void remap_synonym(char *name)
Definition: locale.c:90
#define FOUND_CODEPAGE
Definition: locale.c:107
int atoi(const char *)
#define FOUND_COUNTRY
Definition: locale.c:106
#define strcasecmp
Definition: locale.c:34
static BOOL CALLBACK find_best_locale_proc(HMODULE hModule, LPCSTR type, LPCSTR name, WORD LangID, LONG_PTR lParam)
Definition: locale.c:143
#define MAX_ELEM_LEN
Definition: locale.c:27
int codepage
Definition: win_iconv.c:156
#define LOCALE_IDEFAULTCODEPAGE
Definition: winnls.h:39
#define LOCALE_ILANGUAGE
Definition: winnls.h:25
#define LOCALE_IDEFAULTANSICODEPAGE
Definition: winnls.h:40
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182

Referenced by MSVCRT__create_locale().

Variable Documentation

◆ global_locale

MSVCRT__locale_t global_locale
extern