Commit 8adfd63c authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Return correct strings in setlocale.

parent 0d79b4b6
...@@ -348,6 +348,32 @@ MSVCRT__locale_t get_locale(void) { ...@@ -348,6 +348,32 @@ MSVCRT__locale_t get_locale(void) {
return data->locale; 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.@) * wsetlocale (MSVCRT.@)
...@@ -1020,31 +1046,25 @@ int CDECL _configthreadlocale(int type) ...@@ -1020,31 +1046,25 @@ int CDECL _configthreadlocale(int type)
*/ */
char* CDECL MSVCRT_setlocale(int category, const char* locale) char* CDECL MSVCRT_setlocale(int category, const char* locale)
{ {
static char current_lc_all[MAX_LOCALE_LENGTH];
MSVCRT__locale_t loc, cur; MSVCRT__locale_t loc, cur;
cur = get_locale(); cur = get_locale();
if(locale == NULL) { if(category<MSVCRT_LC_MIN || category>MSVCRT_LC_MAX)
if(category == MSVCRT_LC_ALL) { return NULL;
sprintf(current_lc_all,
"LC_COLLATE=%s;LC_CTYPE=%s;LC_MONETARY=%s;LC_NUMERIC=%s;LC_TIME=%s", if(!locale) {
cur->locinfo->lc_category[MSVCRT_LC_COLLATE].locale, if(category == MSVCRT_LC_ALL)
cur->locinfo->lc_category[MSVCRT_LC_CTYPE].locale, return construct_lc_all(cur);
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;
}
return cur->locinfo->lc_category[category].locale; return cur->locinfo->lc_category[category].locale;
} }
loc = _create_locale(category, locale); loc = _create_locale(category, locale);
if(!loc) if(!loc) {
WARN("%d %s failed\n", category, locale);
return NULL; return NULL;
}
LOCK_LOCALE; LOCK_LOCALE;
...@@ -1163,7 +1183,7 @@ char* CDECL MSVCRT_setlocale(int category, const char* locale) ...@@ -1163,7 +1183,7 @@ char* CDECL MSVCRT_setlocale(int category, const char* locale)
} }
if(category == MSVCRT_LC_ALL) 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; return cur->locinfo->lc_category[category].locale;
} }
...@@ -51,7 +51,7 @@ static void test_setlocale(void) ...@@ -51,7 +51,7 @@ static void test_setlocale(void)
ok(!strcmp(ret, "C"), "ret = %s\n", ret); ok(!strcmp(ret, "C"), "ret = %s\n", ret);
ret = setlocale(LC_ALL, NULL); 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") if(!setlocale(LC_NUMERIC, "Polish")
|| !setlocale(LC_NUMERIC, "Greek") || !setlocale(LC_NUMERIC, "Greek")
...@@ -72,7 +72,7 @@ static void test_setlocale(void) ...@@ -72,7 +72,7 @@ static void test_setlocale(void)
strcpy(buf, ret); strcpy(buf, ret);
ret = setlocale(LC_ALL, buf); 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"); ret = setlocale(LC_ALL, "German");
todo_wine ok(!strcmp(ret, "German_Germany.1252"), "ret = %s\n", ret); todo_wine ok(!strcmp(ret, "German_Germany.1252"), "ret = %s\n", ret);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment