4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
7 * Copyright 2002 Alexandre Julliard for Codeweavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/port.h"
34 #include "winuser.h" /* for RT_STRINGW */
36 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(nls);
44 #define LOCALE_LOCALEINFOFLAGSMASK (LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP|LOCALE_RETURN_NUMBER)
46 extern void CODEPAGE_Init( UINT ansi_cp, UINT oem_cp, UINT mac_cp, UINT unix_cp, LCID lcid );
48 /* Charset to codepage map, sorted by name. */
49 static const struct charset_entry
51 const char *charset_name;
83 { "ISO-8859-1", 28591 },
84 { "ISO-8859-10", 28600 },
85 { "ISO-8859-13", 28603 },
86 { "ISO-8859-14", 28604 },
87 { "ISO-8859-15", 28605 },
88 { "ISO-8859-2", 28592 },
89 { "ISO-8859-3", 28593 },
90 { "ISO-8859-4", 28594 },
91 { "ISO-8859-5", 28595 },
92 { "ISO-8859-6", 28596 },
93 { "ISO-8859-7", 28597 },
94 { "ISO-8859-8", 28598 },
95 { "ISO-8859-9", 28599 },
96 { "ISO_8859-1", 28591 },
97 { "ISO_8859-10", 28600 },
98 { "ISO_8859-13", 28603 },
99 { "ISO_8859-14", 28604 },
100 { "ISO_8859-15", 28605 },
101 { "ISO_8859-2", 28592 },
102 { "ISO_8859-3", 28593 },
103 { "ISO_8859-4", 28594 },
104 { "ISO_8859-5", 28595 },
105 { "ISO_8859-6", 28596 },
106 { "ISO_8859-7", 28597 },
107 { "ISO_8859-8", 28598 },
108 { "ISO_8859-9", 28599 },
114 #define NLS_MAX_LANGUAGES 20
118 LANGID found_lang_id[NLS_MAX_LANGUAGES];
119 char found_language[NLS_MAX_LANGUAGES][3];
120 char found_country[NLS_MAX_LANGUAGES][3];
125 /***********************************************************************
128 * Retrieve the ANSI codepage for a given locale.
130 inline static UINT get_lcid_codepage( LCID lcid )
133 if (!GetLocaleInfoW( lcid, LOCALE_IDEFAULTANSICODEPAGE|LOCALE_RETURN_NUMBER, (WCHAR *)&ret,
134 sizeof(ret)/sizeof(WCHAR) )) ret = 0;
139 /***********************************************************************
140 * create_registry_key
142 * Create the Control Panel\\International registry key.
144 inline static HKEY create_registry_key(void)
146 static const WCHAR intlW[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
147 'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
148 OBJECT_ATTRIBUTES attr;
149 UNICODE_STRING nameW;
152 if (RtlOpenCurrentUser( KEY_ALL_ACCESS, &hkey ) != STATUS_SUCCESS) return 0;
154 attr.Length = sizeof(attr);
155 attr.RootDirectory = hkey;
156 attr.ObjectName = &nameW;
158 attr.SecurityDescriptor = NULL;
159 attr.SecurityQualityOfService = NULL;
160 RtlInitUnicodeString( &nameW, intlW );
162 if (NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ) != STATUS_SUCCESS) hkey = 0;
163 NtClose( attr.RootDirectory );
168 /***********************************************************************
171 * Update registry contents on startup if the user locale has changed.
172 * This simulates the action of the Windows control panel.
174 inline static void update_registry( LCID lcid )
176 static const WCHAR LocaleW[] = {'L','o','c','a','l','e',0};
177 UNICODE_STRING nameW;
180 DWORD count = sizeof(buffer);
183 if (!(hkey = create_registry_key()))
184 return; /* don't do anything if we can't create the registry key */
186 RtlInitUnicodeString( &nameW, LocaleW );
187 count = sizeof(bufferW);
188 if (!NtQueryValueKey(hkey, &nameW, KeyValuePartialInformation, (LPBYTE)bufferW, count, &count))
190 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)bufferW;
191 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &count,
192 (WCHAR *)info->Data, info->DataLength );
194 if (strtol( buffer, NULL, 16 ) == lcid) /* already set correctly */
199 TRACE( "updating registry, locale changed %s -> %08lx\n", buffer, lcid );
201 else TRACE( "updating registry, locale changed none -> %08lx\n", lcid );
203 sprintf( buffer, "%08lx", lcid );
204 RtlMultiByteToUnicodeN( bufferW, sizeof(bufferW), NULL, buffer, strlen(buffer)+1 );
205 NtSetValueKey( hkey, &nameW, 0, REG_SZ, bufferW, (strlenW(bufferW)+1) * sizeof(WCHAR) );
208 #define UPDATE_VALUE(lctype) do { \
209 GetLocaleInfoW( lcid, (lctype)|LOCALE_NOUSEROVERRIDE, bufferW, sizeof(bufferW)/sizeof(WCHAR) ); \
210 SetLocaleInfoW( lcid, (lctype), bufferW ); } while (0)
212 UPDATE_VALUE(LOCALE_SLANGUAGE);
213 UPDATE_VALUE(LOCALE_SCOUNTRY);
214 UPDATE_VALUE(LOCALE_ICOUNTRY);
215 UPDATE_VALUE(LOCALE_S1159);
216 UPDATE_VALUE(LOCALE_S2359);
217 UPDATE_VALUE(LOCALE_STIME);
218 UPDATE_VALUE(LOCALE_ITIME);
219 UPDATE_VALUE(LOCALE_ITLZERO);
220 UPDATE_VALUE(LOCALE_SSHORTDATE);
221 UPDATE_VALUE(LOCALE_IDATE);
222 UPDATE_VALUE(LOCALE_SLONGDATE);
223 UPDATE_VALUE(LOCALE_SDATE);
224 UPDATE_VALUE(LOCALE_SCURRENCY);
225 UPDATE_VALUE(LOCALE_ICURRENCY);
226 UPDATE_VALUE(LOCALE_INEGCURR);
227 UPDATE_VALUE(LOCALE_ICURRDIGITS);
228 UPDATE_VALUE(LOCALE_SDECIMAL);
229 UPDATE_VALUE(LOCALE_SLIST);
230 UPDATE_VALUE(LOCALE_STHOUSAND);
231 UPDATE_VALUE(LOCALE_IDIGITS);
232 UPDATE_VALUE(LOCALE_ILZERO);
233 UPDATE_VALUE(LOCALE_IMEASURE);
238 /***********************************************************************
239 * find_language_id_proc
241 static BOOL CALLBACK find_language_id_proc( HMODULE hModule, LPCSTR type,
242 LPCSTR name, WORD LangID, LPARAM lParam )
244 LANG_FIND_DATA *l_data = (LANG_FIND_DATA *)lParam;
245 LCID lcid = MAKELCID(LangID, SORT_DEFAULT);
246 char buf_language[128];
247 char buf_country[128];
248 char buf_en_language[128];
250 TRACE("%04X\n", (UINT)LangID);
251 if(PRIMARYLANGID(LangID) == LANG_NEUTRAL)
252 return TRUE; /* continue search */
257 GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME|LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP,
258 buf_language, sizeof(buf_language));
259 TRACE("LOCALE_SISO639LANGNAME: %s\n", buf_language);
261 GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME|LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP,
262 buf_country, sizeof(buf_country));
263 TRACE("LOCALE_SISO3166CTRYNAME: %s\n", buf_country);
265 if(l_data->lang && strlen(l_data->lang) > 0 && !strcasecmp(l_data->lang, buf_language))
267 if(l_data->country && strlen(l_data->country) > 0)
269 if(!strcasecmp(l_data->country, buf_country))
271 l_data->found_lang_id[0] = LangID;
273 TRACE("Found lang_id %04X for %s_%s\n", LangID, l_data->lang, l_data->country);
274 return FALSE; /* stop enumeration */
277 else /* l_data->country not specified */
279 if(l_data->n_found < NLS_MAX_LANGUAGES)
281 l_data->found_lang_id[l_data->n_found] = LangID;
282 strncpy(l_data->found_country[l_data->n_found], buf_country, 3);
283 strncpy(l_data->found_language[l_data->n_found], buf_language, 3);
285 TRACE("Found lang_id %04X for %s\n", LangID, l_data->lang);
286 return TRUE; /* continue search */
291 /* Just in case, check LOCALE_SENGLANGUAGE too,
292 * in hope that possible alias name might have that value.
294 buf_en_language[0] = 0;
295 GetLocaleInfoA(lcid, LOCALE_SENGLANGUAGE|LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP,
296 buf_en_language, sizeof(buf_en_language));
297 TRACE("LOCALE_SENGLANGUAGE: %s\n", buf_en_language);
299 if(l_data->lang && strlen(l_data->lang) > 0 && !strcasecmp(l_data->lang, buf_en_language))
301 l_data->found_lang_id[l_data->n_found] = LangID;
302 strncpy(l_data->found_country[l_data->n_found], buf_country, 3);
303 strncpy(l_data->found_language[l_data->n_found], buf_language, 3);
305 TRACE("Found lang_id %04X for %s\n", LangID, l_data->lang);
308 return TRUE; /* continue search */
312 /***********************************************************************
316 * Lang: a string whose two first chars are the iso name of a language.
317 * Country: a string whose two first chars are the iso name of country
318 * Charset: a string defining the chosen charset encoding
319 * Dialect: a string defining a variation of the locale
321 * all those values are from the standardized format of locale
322 * name in unix which is: Lang[_Country][.Charset][@Dialect]
325 * the numeric code of the language used by Windows
327 * FIXME: Charset and Dialect are not handled
329 static LANGID get_language_id(LPCSTR Lang, LPCSTR Country, LPCSTR Charset, LPCSTR Dialect)
331 LANG_FIND_DATA l_data;
332 char lang_string[256];
336 l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
340 memset(&l_data, 0, sizeof(LANG_FIND_DATA));
341 strncpy(l_data.lang, Lang, sizeof(l_data.lang));
343 if(Country && strlen(Country) > 0)
344 strncpy(l_data.country, Country, sizeof(l_data.country));
346 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
347 (LPCSTR)LOCALE_ILANGUAGE, find_language_id_proc, (LPARAM)&l_data);
349 strcpy(lang_string, l_data.lang);
350 if(l_data.country && strlen(l_data.country) > 0)
352 strcat(lang_string, "_");
353 strcat(lang_string, l_data.country);
358 if(l_data.country && strlen(l_data.country) > 0)
360 MESSAGE("Warning: Language '%s' was not found, retrying without country name...\n", lang_string);
361 l_data.country[0] = 0;
362 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
363 (LPCSTR)LOCALE_ILANGUAGE, find_language_id_proc, (LONG)&l_data);
367 /* Re-evaluate lang_string */
368 strcpy(lang_string, l_data.lang);
369 if(l_data.country && strlen(l_data.country) > 0)
371 strcat(lang_string, "_");
372 strcat(lang_string, l_data.country);
377 MESSAGE("Warning: Language '%s' was not recognized, defaulting to English\n", lang_string);
378 l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
382 if(l_data.n_found == 1)
383 TRACE("For language '%s' lang_id %04X was found\n", lang_string, l_data.found_lang_id[0]);
384 else /* l_data->n_found > 1 */
387 MESSAGE("For language '%s' several language ids were found:\n", lang_string);
388 for(i = 0; i < l_data.n_found; i++)
389 MESSAGE("%s_%s - %04X; ", l_data.found_language[i], l_data.found_country[i], l_data.found_lang_id[i]);
391 MESSAGE("\nInstead of using first in the list, suggest to define\n"
392 "your LANG environment variable like this: LANG=%s_%s\n",
393 l_data.found_language[0], l_data.found_country[0]);
397 TRACE("Returning %04X\n", l_data.found_lang_id[0]);
398 return l_data.found_lang_id[0];
402 /***********************************************************************
403 * charset_cmp (internal)
405 static int charset_cmp( const void *name, const void *entry )
407 const struct charset_entry *charset = (struct charset_entry *)entry;
408 return strcasecmp( (char *)name, charset->charset_name );
411 /***********************************************************************
414 static LCID init_default_lcid( UINT *unix_cp )
417 char *lang,*country,*charset,*dialect,*next;
420 if (GetEnvironmentVariableA( "LC_ALL", buf, sizeof(buf) ) ||
421 GetEnvironmentVariableA( "LC_CTYPE", buf, sizeof(buf) ) ||
422 GetEnvironmentVariableA( "LANGUAGE", buf, sizeof(buf) ) ||
423 GetEnvironmentVariableA( "LC_MESSAGES", buf, sizeof(buf) ) ||
424 GetEnvironmentVariableA( "LANG", buf, sizeof(buf) ))
426 if (!strcmp(buf,"POSIX") || !strcmp(buf,"C")) goto done;
431 next=strchr(lang,':'); if (next) *next++='\0';
432 dialect=strchr(lang,'@'); if (dialect) *dialect++='\0';
433 charset=strchr(lang,'.'); if (charset) *charset++='\0';
434 country=strchr(lang,'_'); if (country) *country++='\0';
436 ret = get_language_id(lang, country, charset, dialect);
439 const struct charset_entry *entry;
440 entry = bsearch( charset, charset_names, sizeof(charset_names)/sizeof(charset_names[0]),
441 sizeof(charset_names[0]), charset_cmp );
444 *unix_cp = entry->codepage;
445 TRACE("charset %s was mapped to cp %u\n", charset, *unix_cp);
448 FIXME("charset %s was not recognized\n", charset);
452 } while (lang && !ret);
454 if (!ret) MESSAGE("Warning: language '%s' not recognized, defaulting to English\n", buf);
458 if (!ret) ret = MAKELCID( MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT), SORT_DEFAULT) ;
463 /******************************************************************************
464 * get_locale_value_name
466 * Gets the registry value name for a given lctype.
468 static const WCHAR *get_locale_value_name( DWORD lctype )
470 static const WCHAR iCalendarTypeW[] = {'i','C','a','l','e','n','d','a','r','T','y','p','e',0};
471 static const WCHAR iCountryW[] = {'i','C','o','u','n','t','r','y',0};
472 static const WCHAR iCurrDigitsW[] = {'i','C','u','r','r','D','i','g','i','t','s',0};
473 static const WCHAR iCurrencyW[] = {'i','C','u','r','r','e','n','c','y',0};
474 static const WCHAR iDateW[] = {'i','D','a','t','e',0};
475 static const WCHAR iDigitsW[] = {'i','D','i','g','i','t','s',0};
476 static const WCHAR iFirstDayOfWeekW[] = {'i','F','i','r','s','t','D','a','y','O','f','W','e','e','k',0};
477 static const WCHAR iFirstWeekOfYearW[] = {'i','F','i','r','s','t','W','e','e','k','O','f','Y','e','a','r',0};
478 static const WCHAR iLDateW[] = {'i','L','D','a','t','e',0};
479 static const WCHAR iLZeroW[] = {'i','L','Z','e','r','o',0};
480 static const WCHAR iMeasureW[] = {'i','M','e','a','s','u','r','e',0};
481 static const WCHAR iNegCurrW[] = {'i','N','e','g','C','u','r','r',0};
482 static const WCHAR iNegNumberW[] = {'i','N','e','g','N','u','m','b','e','r',0};
483 static const WCHAR iPaperSizeW[] = {'i','P','a','p','e','r','S','i','z','e',0};
484 static const WCHAR iTLZeroW[] = {'i','T','L','Z','e','r','o',0};
485 static const WCHAR iTimeW[] = {'i','T','i','m','e',0};
486 static const WCHAR s1159W[] = {'s','1','1','5','9',0};
487 static const WCHAR s2359W[] = {'s','2','3','5','9',0};
488 static const WCHAR sCountryW[] = {'s','C','o','u','n','t','r','y',0};
489 static const WCHAR sCurrencyW[] = {'s','C','u','r','r','e','n','c','y',0};
490 static const WCHAR sDateW[] = {'s','D','a','t','e',0};
491 static const WCHAR sDecimalW[] = {'s','D','e','c','i','m','a','l',0};
492 static const WCHAR sGroupingW[] = {'s','G','r','o','u','p','i','n','g',0};
493 static const WCHAR sLanguageW[] = {'s','L','a','n','g','u','a','g','e',0};
494 static const WCHAR sListW[] = {'s','L','i','s','t',0};
495 static const WCHAR sLongDateW[] = {'s','L','o','n','g','D','a','t','e',0};
496 static const WCHAR sMonDecimalSepW[] = {'s','M','o','n','D','e','c','i','m','a','l','S','e','p',0};
497 static const WCHAR sMonGroupingW[] = {'s','M','o','n','G','r','o','u','p','i','n','g',0};
498 static const WCHAR sMonThousandSepW[] = {'s','M','o','n','T','h','o','u','s','a','n','d','S','e','p',0};
499 static const WCHAR sNegativeSignW[] = {'s','N','e','g','a','t','i','v','e','S','i','g','n',0};
500 static const WCHAR sPositiveSignW[] = {'s','P','o','s','i','t','i','v','e','S','i','g','n',0};
501 static const WCHAR sShortDateW[] = {'s','S','h','o','r','t','D','a','t','e',0};
502 static const WCHAR sThousandW[] = {'s','T','h','o','u','s','a','n','d',0};
503 static const WCHAR sTimeFormatW[] = {'s','T','i','m','e','F','o','r','m','a','t',0};
504 static const WCHAR sTimeW[] = {'s','T','i','m','e',0};
505 static const WCHAR sYearMonthW[] = {'s','Y','e','a','r','M','o','n','t','h',0};
507 switch (lctype & ~LOCALE_LOCALEINFOFLAGSMASK)
509 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
510 * the values are stored in the registry, confirmed under Windows.
512 case LOCALE_ICALENDARTYPE: return iCalendarTypeW;
513 case LOCALE_ICURRDIGITS: return iCurrDigitsW;
514 case LOCALE_ICURRENCY: return iCurrencyW;
515 case LOCALE_IDIGITS: return iDigitsW;
516 case LOCALE_IFIRSTDAYOFWEEK: return iFirstDayOfWeekW;
517 case LOCALE_IFIRSTWEEKOFYEAR: return iFirstWeekOfYearW;
518 case LOCALE_ILZERO: return iLZeroW;
519 case LOCALE_IMEASURE: return iMeasureW;
520 case LOCALE_INEGCURR: return iNegCurrW;
521 case LOCALE_INEGNUMBER: return iNegNumberW;
522 case LOCALE_IPAPERSIZE: return iPaperSizeW;
523 case LOCALE_ITIME: return iTimeW;
524 case LOCALE_S1159: return s1159W;
525 case LOCALE_S2359: return s2359W;
526 case LOCALE_SCURRENCY: return sCurrencyW;
527 case LOCALE_SDATE: return sDateW;
528 case LOCALE_SDECIMAL: return sDecimalW;
529 case LOCALE_SGROUPING: return sGroupingW;
530 case LOCALE_SLIST: return sListW;
531 case LOCALE_SLONGDATE: return sLongDateW;
532 case LOCALE_SMONDECIMALSEP: return sMonDecimalSepW;
533 case LOCALE_SMONGROUPING: return sMonGroupingW;
534 case LOCALE_SMONTHOUSANDSEP: return sMonThousandSepW;
535 case LOCALE_SNEGATIVESIGN: return sNegativeSignW;
536 case LOCALE_SPOSITIVESIGN: return sPositiveSignW;
537 case LOCALE_SSHORTDATE: return sShortDateW;
538 case LOCALE_STHOUSAND: return sThousandW;
539 case LOCALE_STIME: return sTimeW;
540 case LOCALE_STIMEFORMAT: return sTimeFormatW;
541 case LOCALE_SYEARMONTH: return sYearMonthW;
543 /* The following are not listed under MSDN as supported,
544 * but seem to be used and also stored in the registry.
546 case LOCALE_ICOUNTRY: return iCountryW;
547 case LOCALE_IDATE: return iDateW;
548 case LOCALE_ILDATE: return iLDateW;
549 case LOCALE_ITLZERO: return iTLZeroW;
550 case LOCALE_SCOUNTRY: return sCountryW;
551 case LOCALE_SLANGUAGE: return sLanguageW;
557 /******************************************************************************
558 * get_registry_locale_info
560 * Retrieve user-modified locale info from the registry.
561 * Return length, 0 on error, -1 if not found.
563 static INT get_registry_locale_info( LPCWSTR value, LPWSTR buffer, INT len )
569 UNICODE_STRING nameW;
570 KEY_VALUE_PARTIAL_INFORMATION *info;
571 static const int info_size = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
573 if (!(hkey = create_registry_key())) return -1;
575 RtlInitUnicodeString( &nameW, value );
576 size = info_size + len * sizeof(WCHAR);
578 if (!(info = HeapAlloc( GetProcessHeap(), 0, size )))
581 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
585 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, info, size, &size );
586 if (status == STATUS_BUFFER_OVERFLOW && !buffer) status = 0;
590 ret = (size - info_size) / sizeof(WCHAR);
591 /* append terminating null if needed */
592 if (!ret || ((WCHAR *)info->Data)[ret-1])
594 if (ret < len || !buffer) ret++;
597 SetLastError( ERROR_INSUFFICIENT_BUFFER );
603 memcpy( buffer, info->Data, (ret-1) * sizeof(WCHAR) );
609 if (status == STATUS_OBJECT_NAME_NOT_FOUND) ret = -1;
612 SetLastError( RtlNtStatusToDosError(status) );
617 HeapFree( GetProcessHeap(), 0, info );
622 /******************************************************************************
623 * GetLocaleInfoA (KERNEL32.@)
626 * LOCALE_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
628 * MS online documentation states that the string returned is NULL terminated
629 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
630 * terminated string".
632 INT WINAPI GetLocaleInfoA( LCID lcid, LCTYPE lctype, LPSTR buffer, INT len )
637 if (len < 0 || (len && !buffer))
639 SetLastError( ERROR_INVALID_PARAMETER );
642 if (!len) buffer = NULL;
644 if (!(lenW = GetLocaleInfoW( lcid, lctype, NULL, 0 ))) return 0;
646 if (!(bufferW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) )))
648 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
651 if ((ret = GetLocaleInfoW( lcid, lctype, bufferW, lenW )))
653 if ((lctype & LOCALE_RETURN_NUMBER) ||
654 ((lctype & ~LOCALE_LOCALEINFOFLAGSMASK) == LOCALE_FONTSIGNATURE))
656 /* it's not an ASCII string, just bytes */
657 ret *= sizeof(WCHAR);
660 if (ret <= len) memcpy( buffer, bufferW, ret );
663 SetLastError( ERROR_INSUFFICIENT_BUFFER );
670 UINT codepage = CP_ACP;
671 if (!(lctype & LOCALE_USE_CP_ACP)) codepage = get_lcid_codepage( lcid );
672 ret = WideCharToMultiByte( codepage, 0, bufferW, ret, buffer, len, NULL, NULL );
675 HeapFree( GetProcessHeap(), 0, bufferW );
680 /******************************************************************************
681 * GetLocaleInfoW (KERNEL32.@)
684 * LOCALE_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
686 * MS online documentation states that the string returned is NULL terminated
687 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
688 * terminated string".
690 INT WINAPI GetLocaleInfoW( LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len )
701 if (len < 0 || (len && !buffer))
703 SetLastError( ERROR_INVALID_PARAMETER );
706 if (!len) buffer = NULL;
708 if (lcid == LOCALE_NEUTRAL || lcid == LOCALE_SYSTEM_DEFAULT) lcid = GetSystemDefaultLCID();
709 else if (lcid == LOCALE_USER_DEFAULT) lcid = GetUserDefaultLCID();
711 lcflags = lctype & LOCALE_LOCALEINFOFLAGSMASK;
712 lctype &= ~LOCALE_LOCALEINFOFLAGSMASK;
714 /* first check for overrides in the registry */
716 if (!(lcflags & LOCALE_NOUSEROVERRIDE) && lcid == GetUserDefaultLCID())
718 const WCHAR *value = get_locale_value_name(lctype);
720 if (value && ((ret = get_registry_locale_info( value, buffer, len )) != -1)) return ret;
723 /* now load it from kernel resources */
725 lang_id = LANGIDFROMLCID( lcid );
727 /* replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
728 if (SUBLANGID(lang_id) == SUBLANG_NEUTRAL)
729 lang_id = MAKELANGID(PRIMARYLANGID(lang_id), SUBLANG_DEFAULT);
731 hModule = GetModuleHandleA( "kernel32.dll" );
732 if (!(hrsrc = FindResourceExW( hModule, RT_STRINGW, (LPCWSTR)((lctype >> 4) + 1), lang_id )))
734 SetLastError( ERROR_INVALID_FLAGS ); /* no such lctype */
737 if (!(hmem = LoadResource( hModule, hrsrc )))
740 p = LockResource( hmem );
741 for (i = 0; i < (lctype & 0x0f); i++) p += *p + 1;
743 if (lcflags & LOCALE_RETURN_NUMBER) ret = sizeof(UINT)/sizeof(WCHAR);
744 else ret = (lctype == LOCALE_FONTSIGNATURE) ? *p : *p + 1;
746 if (!buffer) return ret;
750 SetLastError( ERROR_INSUFFICIENT_BUFFER );
754 if (lcflags & LOCALE_RETURN_NUMBER)
757 WCHAR *end, *tmp = HeapAlloc( GetProcessHeap(), 0, (*p + 1) * sizeof(WCHAR) );
759 memcpy( tmp, p + 1, *p * sizeof(WCHAR) );
761 number = strtolW( tmp, &end, 10 );
763 memcpy( buffer, &number, sizeof(number) );
764 else /* invalid number */
766 SetLastError( ERROR_INVALID_FLAGS );
769 HeapFree( GetProcessHeap(), 0, tmp );
771 TRACE( "(lcid=0x%lx,lctype=0x%lx,%p,%d) returning number %d\n",
772 lcid, lctype, buffer, len, number );
776 memcpy( buffer, p + 1, *p * sizeof(WCHAR) );
777 if (lctype != LOCALE_FONTSIGNATURE) buffer[ret-1] = 0;
779 TRACE( "(lcid=0x%lx,lctype=0x%lx,%p,%d) returning %d %s\n",
780 lcid, lctype, buffer, len, ret, debugstr_w(buffer) );
786 /******************************************************************************
787 * SetLocaleInfoA [KERNEL32.@]
789 BOOL WINAPI SetLocaleInfoA(LCID lcid, LCTYPE lctype, LPCSTR data)
791 UINT codepage = CP_ACP;
796 if (lcid == LOCALE_NEUTRAL || lcid == LOCALE_SYSTEM_DEFAULT) lcid = GetSystemDefaultLCID();
797 else if (lcid == LOCALE_USER_DEFAULT) lcid = GetUserDefaultLCID();
799 if (!(lctype & LOCALE_USE_CP_ACP)) codepage = get_lcid_codepage( lcid );
800 len = MultiByteToWideChar( codepage, 0, data, -1, NULL, 0 );
801 if (!(strW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
803 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
806 MultiByteToWideChar( codepage, 0, data, -1, strW, len );
807 ret = SetLocaleInfoW( lcid, lctype, strW );
808 HeapFree( GetProcessHeap(), 0, strW );
813 /******************************************************************************
814 * SetLocaleInfoW (KERNEL32.@)
816 BOOL WINAPI SetLocaleInfoW( LCID lcid, LCTYPE lctype, LPCWSTR data )
819 const WCHAR intlW[] = {'i','n','t','l',0 };
820 UNICODE_STRING valueW;
824 if (lcid == LOCALE_NEUTRAL || lcid == LOCALE_SYSTEM_DEFAULT) lcid = GetSystemDefaultLCID();
825 else if (lcid == LOCALE_USER_DEFAULT) lcid = GetUserDefaultLCID();
827 if (!(value = get_locale_value_name( lctype )))
829 SetLastError( ERROR_INVALID_PARAMETER );
832 if (lcid != GetUserDefaultLCID()) return TRUE; /* fake success */
834 TRACE("setting %lx to %s\n", lctype, debugstr_w(data) );
836 /* FIXME: should check that data to set is sane */
838 /* FIXME: profile functions should map to registry */
839 WriteProfileStringW( intlW, value, data );
841 if (!(hkey = create_registry_key())) return FALSE;
842 RtlInitUnicodeString( &valueW, value );
843 status = NtSetValueKey( hkey, &valueW, 0, REG_SZ, data, (strlenW(data)+1)*sizeof(WCHAR) );
846 if (status) SetLastError( RtlNtStatusToDosError(status) );
852 /***********************************************************************
853 * GetThreadLocale (KERNEL32.@)
855 LCID WINAPI GetThreadLocale(void)
857 LCID ret = NtCurrentTeb()->CurrentLocale;
858 if (!ret) NtCurrentTeb()->CurrentLocale = ret = GetUserDefaultLCID();
863 /**********************************************************************
864 * SetThreadLocale (KERNEL32.@)
867 * check if lcid is a valid cp
869 BOOL WINAPI SetThreadLocale( LCID lcid ) /* [in] Locale identifier */
871 if (lcid == LOCALE_NEUTRAL || lcid == LOCALE_SYSTEM_DEFAULT) lcid = GetSystemDefaultLCID();
872 else if (lcid == LOCALE_USER_DEFAULT) lcid = GetUserDefaultLCID();
874 NtCurrentTeb()->CurrentLocale = lcid;
875 NtCurrentTeb()->code_page = get_lcid_codepage( lcid );
880 /******************************************************************************
881 * ConvertDefaultLocale (KERNEL32.@)
883 LCID WINAPI ConvertDefaultLocale( LCID lcid )
887 case LOCALE_SYSTEM_DEFAULT:
888 return GetSystemDefaultLCID();
889 case LOCALE_USER_DEFAULT:
890 return GetUserDefaultLCID();
892 return MAKELCID (LANG_NEUTRAL, SUBLANG_NEUTRAL);
894 return MAKELANGID( PRIMARYLANGID(lcid), SUBLANG_NEUTRAL);
898 /******************************************************************************
899 * IsValidLocale (KERNEL32.@)
901 BOOL WINAPI IsValidLocale( LCID lcid, DWORD flags )
903 /* check if language is registered in the kernel32 resources */
904 return FindResourceExW( GetModuleHandleA("KERNEL32"), RT_STRINGW,
905 (LPCWSTR)LOCALE_ILANGUAGE, LANGIDFROMLCID(lcid)) != 0;
909 static BOOL CALLBACK enum_lang_proc_a( HMODULE hModule, LPCSTR type,
910 LPCSTR name, WORD LangID, LONG lParam )
912 LOCALE_ENUMPROCA lpfnLocaleEnum = (LOCALE_ENUMPROCA)lParam;
915 sprintf(buf, "%08x", (UINT)LangID);
916 return lpfnLocaleEnum( buf );
919 static BOOL CALLBACK enum_lang_proc_w( HMODULE hModule, LPCWSTR type,
920 LPCWSTR name, WORD LangID, LONG lParam )
922 static const WCHAR formatW[] = {'%','0','8','x',0};
923 LOCALE_ENUMPROCW lpfnLocaleEnum = (LOCALE_ENUMPROCW)lParam;
925 sprintfW( buf, formatW, (UINT)LangID );
926 return lpfnLocaleEnum( buf );
929 /******************************************************************************
930 * EnumSystemLocalesA (KERNEL32.@)
932 BOOL WINAPI EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum,
935 TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
936 EnumResourceLanguagesA( GetModuleHandleA("KERNEL32"), RT_STRINGA,
937 (LPCSTR)LOCALE_ILANGUAGE, enum_lang_proc_a,
938 (LONG)lpfnLocaleEnum);
943 /******************************************************************************
944 * EnumSystemLocalesW (KERNEL32.@)
946 BOOL WINAPI EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum, DWORD flags )
948 TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
949 EnumResourceLanguagesW( GetModuleHandleA("KERNEL32"), RT_STRINGW,
950 (LPCWSTR)LOCALE_ILANGUAGE, enum_lang_proc_w,
951 (LONG)lpfnLocaleEnum);
956 /***********************************************************************
957 * VerLanguageNameA (KERNEL32.@)
959 DWORD WINAPI VerLanguageNameA( UINT wLang, LPSTR szLang, UINT nSize )
961 return GetLocaleInfoA( MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize );
965 /***********************************************************************
966 * VerLanguageNameW (KERNEL32.@)
968 DWORD WINAPI VerLanguageNameW( UINT wLang, LPWSTR szLang, UINT nSize )
970 return GetLocaleInfoW( MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize );
974 /******************************************************************************
975 * GetStringTypeW (KERNEL32.@)
977 BOOL WINAPI GetStringTypeW( DWORD type, LPCWSTR src, INT count, LPWORD chartype )
979 if (count == -1) count = strlenW(src) + 1;
983 while (count--) *chartype++ = get_char_typeW( *src++ ) & 0xfff;
986 while (count--) *chartype++ = get_char_typeW( *src++ ) >> 12;
990 WARN("CT_CTYPE3: semi-stub.\n");
994 WORD type1, type3 = 0; /* C3_NOTAPPLICABLE */
996 type1 = get_char_typeW( *src++ ) & 0xfff;
997 /* try to construct type3 from type1 */
998 if(type1 & C1_SPACE) type3 |= C3_SYMBOL;
999 if(type1 & C1_ALPHA) type3 |= C3_ALPHA;
1000 if ((c>=0x30A0)&&(c<=0x30FF)) type3 |= C3_KATAKANA;
1001 if ((c>=0x3040)&&(c<=0x309F)) type3 |= C3_HIRAGANA;
1002 if ((c>=0x4E00)&&(c<=0x9FAF)) type3 |= C3_IDEOGRAPH;
1003 if ((c>=0x0600)&&(c<=0x06FF)) type3 |= C3_KASHIDA;
1004 if ((c>=0x3000)&&(c<=0x303F)) type3 |= C3_SYMBOL;
1006 if ((c>=0xFF00)&&(c<=0xFF60)) type3 |= C3_FULLWIDTH;
1007 if ((c>=0xFF00)&&(c<=0xFF20)) type3 |= C3_SYMBOL;
1008 if ((c>=0xFF3B)&&(c<=0xFF40)) type3 |= C3_SYMBOL;
1009 if ((c>=0xFF5B)&&(c<=0xFF60)) type3 |= C3_SYMBOL;
1010 if ((c>=0xFF21)&&(c<=0xFF3A)) type3 |= C3_ALPHA;
1011 if ((c>=0xFF41)&&(c<=0xFF5A)) type3 |= C3_ALPHA;
1012 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_FULLWIDTH;
1013 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_SYMBOL;
1015 if ((c>=0xFF61)&&(c<=0xFFDC)) type3 |= C3_HALFWIDTH;
1016 if ((c>=0xFF61)&&(c<=0xFF64)) type3 |= C3_SYMBOL;
1017 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_KATAKANA;
1018 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_ALPHA;
1019 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_HALFWIDTH;
1020 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_SYMBOL;
1021 *chartype++ = type3;
1026 SetLastError( ERROR_INVALID_PARAMETER );
1033 /******************************************************************************
1034 * GetStringTypeExW (KERNEL32.@)
1036 BOOL WINAPI GetStringTypeExW( LCID locale, DWORD type, LPCWSTR src, INT count, LPWORD chartype )
1038 /* locale is ignored for Unicode */
1039 return GetStringTypeW( type, src, count, chartype );
1043 /******************************************************************************
1044 * GetStringTypeA (KERNEL32.@)
1046 BOOL WINAPI GetStringTypeA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
1053 if(count == -1) count = strlen(src) + 1;
1055 if (!(cp = get_lcid_codepage( locale )))
1057 FIXME("For locale %04lx using current ANSI code page\n", locale);
1061 countW = MultiByteToWideChar(cp, 0, src, count, NULL, 0);
1062 if((srcW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
1064 MultiByteToWideChar(cp, 0, src, count, srcW, countW);
1066 * NOTE: the target buffer has 1 word for each CHARACTER in the source
1067 * string, with multibyte characters there maybe be more bytes in count
1068 * than character space in the buffer!
1070 ret = GetStringTypeW(type, srcW, countW, chartype);
1071 HeapFree(GetProcessHeap(), 0, srcW);
1076 /******************************************************************************
1077 * GetStringTypeExA (KERNEL32.@)
1079 BOOL WINAPI GetStringTypeExA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
1081 return GetStringTypeA(locale, type, src, count, chartype);
1085 /*************************************************************************
1086 * LCMapStringW (KERNEL32.@)
1088 INT WINAPI LCMapStringW(LCID lcid, DWORD flags, LPCWSTR src, INT srclen,
1089 LPWSTR dst, INT dstlen)
1093 if (!src || !srclen || dstlen < 0)
1095 SetLastError(ERROR_INVALID_PARAMETER);
1099 /* mutually exclusive flags */
1100 if ((flags & (LCMAP_LOWERCASE | LCMAP_UPPERCASE)) == (LCMAP_LOWERCASE | LCMAP_UPPERCASE) ||
1101 (flags & (LCMAP_HIRAGANA | LCMAP_KATAKANA)) == (LCMAP_HIRAGANA | LCMAP_KATAKANA) ||
1102 (flags & (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH)) == (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH) ||
1103 (flags & (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE)) == (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE))
1105 SetLastError(ERROR_INVALID_FLAGS);
1109 if (!dstlen) dst = NULL;
1111 if (lcid == LOCALE_NEUTRAL || lcid == LOCALE_SYSTEM_DEFAULT) lcid = GetSystemDefaultLCID();
1112 else if (lcid == LOCALE_USER_DEFAULT) lcid = GetUserDefaultLCID();
1114 if (flags & LCMAP_SORTKEY)
1118 SetLastError(ERROR_INVALID_FLAGS);
1122 if (srclen < 0) srclen = strlenW(src);
1124 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1125 lcid, flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
1127 return wine_get_sortkey(flags, src, srclen, (char *)dst, dstlen);
1130 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
1131 if (flags & SORT_STRINGSORT)
1133 SetLastError(ERROR_INVALID_FLAGS);
1137 if (srclen < 0) srclen = strlenW(src) + 1;
1139 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1140 lcid, flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
1142 if (!dst) /* return required string length */
1146 for (len = 0; srclen; src++, srclen--)
1149 /* tests show that win2k just ignores NORM_IGNORENONSPACE,
1150 * and skips white space and punctuation characters for
1151 * NORM_IGNORESYMBOLS.
1153 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1160 if (flags & LCMAP_UPPERCASE)
1162 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
1165 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1167 *dst_ptr++ = toupperW(wch);
1171 else if (flags & LCMAP_LOWERCASE)
1173 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
1176 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1178 *dst_ptr++ = tolowerW(wch);
1186 SetLastError(ERROR_INVALID_FLAGS);
1189 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
1192 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1199 return dst_ptr - dst;
1202 /*************************************************************************
1203 * LCMapStringA (KERNEL32.@)
1205 INT WINAPI LCMapStringA(LCID lcid, DWORD flags, LPCSTR src, INT srclen,
1206 LPSTR dst, INT dstlen)
1210 INT ret = 0, srclenW, dstlenW;
1213 if (!src || !srclen || dstlen < 0)
1215 SetLastError(ERROR_INVALID_PARAMETER);
1219 GetLocaleInfoW(lcid, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
1220 (WCHAR *)&locale_cp, (sizeof(locale_cp)/sizeof(WCHAR)));
1222 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, bufW, 128);
1227 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, NULL, 0);
1228 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
1231 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1234 MultiByteToWideChar(locale_cp, 0, src, srclen, srcW, srclenW);
1237 if (flags & LCMAP_SORTKEY)
1241 SetLastError(ERROR_INVALID_FLAGS);
1242 goto map_string_exit;
1244 ret = wine_get_sortkey(flags, srcW, srclenW, dst, dstlen);
1245 goto map_string_exit;
1248 if (flags & SORT_STRINGSORT)
1250 SetLastError(ERROR_INVALID_FLAGS);
1251 goto map_string_exit;
1254 dstlenW = LCMapStringW(lcid, flags, srcW, srclenW, NULL, 0);
1255 dstW = HeapAlloc(GetProcessHeap(), 0, dstlenW * sizeof(WCHAR));
1258 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1259 goto map_string_exit;
1262 LCMapStringW(lcid, flags, srcW, srclenW, dstW, dstlenW);
1263 ret = WideCharToMultiByte(locale_cp, 0, dstW, dstlenW, dst, dstlen, NULL, NULL);
1264 HeapFree(GetProcessHeap(), 0, dstW);
1267 if (srcW != bufW) HeapFree(GetProcessHeap(), 0, srcW);
1271 /******************************************************************************
1272 * CompareStringW (KERNEL32.@)
1274 INT WINAPI CompareStringW(LCID lcid, DWORD style,
1275 LPCWSTR str1, INT len1, LPCWSTR str2, INT len2)
1281 SetLastError(ERROR_INVALID_PARAMETER);
1285 if (len1 < 0) len1 = lstrlenW(str1);
1286 if (len2 < 0) len2 = lstrlenW(str2);
1288 len = (len1 < len2) ? len1 : len2;
1289 ret = (style & NORM_IGNORECASE) ? strncmpiW(str1, str2, len) :
1290 strncmpW(str1, str2, len);
1292 if (ret) /* need to translate result */
1293 return (ret < 0) ? CSTR_LESS_THAN : CSTR_GREATER_THAN;
1295 if (len1 == len2) return CSTR_EQUAL;
1296 /* the longer one is lexically greater */
1297 return (len1 < len2) ? CSTR_LESS_THAN : CSTR_GREATER_THAN;
1300 /******************************************************************************
1301 * CompareStringA (KERNEL32.@)
1303 INT WINAPI CompareStringA(LCID lcid, DWORD style,
1304 LPCSTR str1, INT len1, LPCSTR str2, INT len2)
1306 WCHAR buf1W[128], buf2W[128];
1307 LPWSTR str1W, str2W;
1308 INT len1W, len2W, ret;
1313 SetLastError(ERROR_INVALID_PARAMETER);
1317 if (len1 < 0) len1 = strlen(str1);
1318 if (len2 < 0) len2 = strlen(str2);
1320 GetLocaleInfoW(lcid, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
1321 (WCHAR *)&locale_cp, (sizeof(locale_cp)/sizeof(WCHAR)));
1323 len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, buf1W, 128);
1328 len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, NULL, 0);
1329 str1W = HeapAlloc(GetProcessHeap(), 0, len1W * sizeof(WCHAR));
1332 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1335 MultiByteToWideChar(locale_cp, 0, str1, len1, str1W, len1W);
1337 len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, buf2W, 128);
1342 len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, NULL, 0);
1343 str2W = HeapAlloc(GetProcessHeap(), 0, len2W * sizeof(WCHAR));
1346 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
1347 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1350 MultiByteToWideChar(locale_cp, 0, str2, len2, str2W, len2W);
1353 ret = CompareStringW(lcid, style, str1W, len1W, str2W, len2W);
1355 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
1356 if (str2W != buf2W) HeapFree(GetProcessHeap(), 0, str2W);
1360 /*************************************************************************
1361 * lstrcmp (KERNEL32.@)
1362 * lstrcmpA (KERNEL32.@)
1364 int WINAPI lstrcmpA(LPCSTR str1, LPCSTR str2)
1366 int ret = CompareStringA(GetThreadLocale(), 0, str1, -1, str2, -1);
1371 /*************************************************************************
1372 * lstrcmpi (KERNEL32.@)
1373 * lstrcmpiA (KERNEL32.@)
1375 int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
1377 int ret = CompareStringA(GetThreadLocale(), NORM_IGNORECASE, str1, -1, str2, -1);
1382 /*************************************************************************
1383 * lstrcmpW (KERNEL32.@)
1385 int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
1387 int ret = CompareStringW(GetThreadLocale(), 0, str1, -1, str2, -1);
1392 /*************************************************************************
1393 * lstrcmpiW (KERNEL32.@)
1395 int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
1397 int ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, -1, str2, -1);
1402 /******************************************************************************
1405 void LOCALE_Init(void)
1407 UINT ansi_cp = 1252, oem_cp = 437, mac_cp = 10000, unix_cp = -1;
1408 LCID lcid = init_default_lcid( &unix_cp );
1410 NtSetDefaultLocale( FALSE, lcid );
1411 NtSetDefaultLocale( TRUE, lcid );
1413 GetLocaleInfoW( lcid, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
1414 (LPWSTR)&ansi_cp, sizeof(ansi_cp)/sizeof(WCHAR) );
1415 GetLocaleInfoW( lcid, LOCALE_IDEFAULTMACCODEPAGE | LOCALE_RETURN_NUMBER,
1416 (LPWSTR)&mac_cp, sizeof(mac_cp)/sizeof(WCHAR) );
1417 GetLocaleInfoW( lcid, LOCALE_IDEFAULTCODEPAGE | LOCALE_RETURN_NUMBER,
1418 (LPWSTR)&oem_cp, sizeof(oem_cp)/sizeof(WCHAR) );
1420 GetLocaleInfoW( lcid, LOCALE_IDEFAULTUNIXCODEPAGE | LOCALE_RETURN_NUMBER,
1421 (LPWSTR)&unix_cp, sizeof(unix_cp)/sizeof(WCHAR) );
1423 CODEPAGE_Init( ansi_cp, oem_cp, mac_cp, unix_cp, lcid );
1424 update_registry( lcid );
1427 /******************************************************************************
1428 * EnumSystemLanguageGroupsA (KERNEL32.@)
1430 BOOL WINAPI EnumSystemLanguageGroupsA(
1431 LANGUAGEGROUP_ENUMPROCA pLangGroupEnumProc, /* [in] callback function */
1432 DWORD dwFlags, /* [in] language groups */
1433 LONG_PTR lParam /* [in] callback parameter */
1437 SetLastError( ERROR_INVALID_PARAMETER );
1441 /******************************************************************************
1442 * EnumSystemLanguageGroupsW (KERNEL32.@)
1444 BOOL WINAPI EnumSystemLanguageGroupsW(
1445 LANGUAGEGROUP_ENUMPROCW pLangGroupEnumProc, /* [in] callback function */
1446 DWORD dwFlags, /* [in] language groups */
1447 LONG_PTR lParam /* [in] callback parameter */
1451 SetLastError( ERROR_INVALID_PARAMETER );
1455 /******************************************************************************
1456 * InvalidateNLSCache (KERNEL32.@)
1458 BOOL WINAPI InvalidateNLSCache(void)