From 8adfd63c2156a95bf5eddb2b283cfd14ff195da3 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Mon, 19 Apr 2010 10:58:51 +0200 Subject: [PATCH] msvcrt: Return correct strings in setlocale. --- dlls/msvcrt/locale.c | 50 ++++++++++++++++++++++++++------------ dlls/msvcrt/tests/locale.c | 4 +-- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c index fe77b83ba64..84bd73b495d 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; ilocinfo->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); + if(categoryMSVCRT_LC_MAX) + return NULL; - return current_lc_all; - } + 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 45ab9b750f0..4c4b7a952d3 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);