Piotr Caban : msvcrt: Return correct strings in setlocale.
Alexandre Julliard
julliard at winehq.org
Mon Apr 19 11:51:17 CDT 2010
Module: wine
Branch: master
Commit: 8adfd63c2156a95bf5eddb2b283cfd14ff195da3
URL: http://source.winehq.org/git/wine.git/?a=commit;h=8adfd63c2156a95bf5eddb2b283cfd14ff195da3
Author: Piotr Caban <piotr at codeweavers.com>
Date: Mon Apr 19 10:58:51 2010 +0200
msvcrt: Return correct strings in setlocale.
---
dlls/msvcrt/locale.c | 52 ++++++++++++++++++++++++++++++-------------
dlls/msvcrt/tests/locale.c | 4 +-
2 files changed, 38 insertions(+), 18 deletions(-)
diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c
index fe77b83..84bd73b 100644
--- a/dlls/msvcrt/locale.c
+++ b/dlls/msvcrt/locale.c
@@ -348,6 +348,32 @@ MSVCRT__locale_t get_locale(void) {
return data->locale;
}
+/* INTERNAL: constructs string returned by setlocale */
+static inline char* construct_lc_all(MSVCRT__locale_t cur) {
+ static char current_lc_all[MAX_LOCALE_LENGTH];
+
+ int i;
+
+ for(i=MSVCRT_LC_MIN+1; i<MSVCRT_LC_MAX; i++) {
+ if(strcmp(cur->locinfo->lc_category[i].locale,
+ cur->locinfo->lc_category[i+1].locale))
+ break;
+ }
+
+ if(i==MSVCRT_LC_MAX)
+ return cur->locinfo->lc_category[MSVCRT_LC_COLLATE].locale;
+
+ sprintf(current_lc_all,
+ "LC_COLLATE=%s;LC_CTYPE=%s;LC_MONETARY=%s;LC_NUMERIC=%s;LC_TIME=%s",
+ cur->locinfo->lc_category[MSVCRT_LC_COLLATE].locale,
+ cur->locinfo->lc_category[MSVCRT_LC_CTYPE].locale,
+ cur->locinfo->lc_category[MSVCRT_LC_MONETARY].locale,
+ cur->locinfo->lc_category[MSVCRT_LC_NUMERIC].locale,
+ cur->locinfo->lc_category[MSVCRT_LC_TIME].locale);
+
+ return current_lc_all;
+}
+
/*********************************************************************
* wsetlocale (MSVCRT.@)
@@ -1020,31 +1046,25 @@ int CDECL _configthreadlocale(int type)
*/
char* CDECL MSVCRT_setlocale(int category, const char* locale)
{
- static char current_lc_all[MAX_LOCALE_LENGTH];
-
MSVCRT__locale_t loc, cur;
cur = get_locale();
- if(locale == NULL) {
- if(category == MSVCRT_LC_ALL) {
- sprintf(current_lc_all,
- "LC_COLLATE=%s;LC_CTYPE=%s;LC_MONETARY=%s;LC_NUMERIC=%s;LC_TIME=%s",
- cur->locinfo->lc_category[MSVCRT_LC_COLLATE].locale,
- cur->locinfo->lc_category[MSVCRT_LC_CTYPE].locale,
- cur->locinfo->lc_category[MSVCRT_LC_MONETARY].locale,
- cur->locinfo->lc_category[MSVCRT_LC_NUMERIC].locale,
- cur->locinfo->lc_category[MSVCRT_LC_TIME].locale);
-
- return current_lc_all;
- }
+ if(category<MSVCRT_LC_MIN || category>MSVCRT_LC_MAX)
+ return NULL;
+
+ if(!locale) {
+ if(category == MSVCRT_LC_ALL)
+ return construct_lc_all(cur);
return cur->locinfo->lc_category[category].locale;
}
loc = _create_locale(category, locale);
- if(!loc)
+ if(!loc) {
+ WARN("%d %s failed\n", category, locale);
return NULL;
+ }
LOCK_LOCALE;
@@ -1163,7 +1183,7 @@ char* CDECL MSVCRT_setlocale(int category, const char* locale)
}
if(category == MSVCRT_LC_ALL)
- return cur->locinfo->lc_category[MSVCRT_LC_COLLATE].locale;
+ return construct_lc_all(cur);
return cur->locinfo->lc_category[category].locale;
}
diff --git a/dlls/msvcrt/tests/locale.c b/dlls/msvcrt/tests/locale.c
index 45ab9b7..4c4b7a9 100644
--- a/dlls/msvcrt/tests/locale.c
+++ b/dlls/msvcrt/tests/locale.c
@@ -51,7 +51,7 @@ static void test_setlocale(void)
ok(!strcmp(ret, "C"), "ret = %s\n", ret);
ret = setlocale(LC_ALL, NULL);
- todo_wine ok(!strcmp(ret, "C"), "ret = %s\n", ret);
+ ok(!strcmp(ret, "C"), "ret = %s\n", ret);
if(!setlocale(LC_NUMERIC, "Polish")
|| !setlocale(LC_NUMERIC, "Greek")
@@ -72,7 +72,7 @@ static void test_setlocale(void)
strcpy(buf, ret);
ret = setlocale(LC_ALL, buf);
- todo_wine ok(!strcmp(ret, lc_all), "ret = %s\n", ret);
+ ok(!strcmp(ret, lc_all), "ret = %s\n", ret);
ret = setlocale(LC_ALL, "German");
todo_wine ok(!strcmp(ret, "German_Germany.1252"), "ret = %s\n", ret);
More information about the wine-cvs
mailing list