Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/ucrtbase/tests/misc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index 083be42f42..d6fdf271e0 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -29,6 +29,7 @@ #include <fcntl.h> #include <time.h> #include <direct.h> +#include <locale.h>
#include <windef.h> #include <winbase.h> @@ -162,6 +163,7 @@ static int* (CDECL *p_errno)(void); static char* (CDECL *p_asctime)(const struct tm *); static size_t (__cdecl *p_strftime)(char *, size_t, const char *, const struct tm *); static size_t (__cdecl *p__Strftime)(char*, size_t, const char*, const struct tm*, void*); +static char* (__cdecl *p_setlocale)(int, const char*); static struct tm* (__cdecl *p__gmtime32)(const __time32_t*); static void (CDECL *p_exit)(int); static int (CDECL *p__crt_atexit)(void (CDECL*)(void)); @@ -538,6 +540,7 @@ static BOOL init(void) p_asctime = (void*)GetProcAddress(module, "asctime"); p_strftime = (void*)GetProcAddress(module, "strftime"); p__Strftime = (void*)GetProcAddress(module, "_Strftime"); + p_setlocale = (void*)GetProcAddress(module, "setlocale"); p__gmtime32 = (void*)GetProcAddress(module, "_gmtime32"); p__crt_atexit = (void*)GetProcAddress(module, "_crt_atexit"); p_exit = (void*)GetProcAddress(module, "exit"); @@ -1185,6 +1188,18 @@ static void test_strftime(void) i, j, buf, tests_yweek[i].ret[j]); } } + + if(!p_setlocale(LC_ALL, "fr-FR")) { + skip("fr-FR locale not available\n"); + return; + } + ret = p_strftime(buf, sizeof(buf), "%c", &epoch); + ok(ret == 19, "ret = %d\n", ret); + ok(!strcmp(buf, "01/01/1970 00:00:00"), "buf = "%s", expected "%s"\n", buf, "01/01/1970 00:00:00"); + ret = p_strftime(buf, sizeof(buf), "%r", &epoch); + todo_wine ok(ret == 8, "ret = %d\n", ret); + todo_wine ok(!strcmp(buf, "00:00:00"), "buf = "%s", expected "%s"\n", buf, "00:00:00"); + p_setlocale(LC_ALL, "C"); }
static LONG* get_failures_counter(HANDLE *map)
Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/msvcrt/locale.c | 167 ++++++++++++++++++++++--------------------- 1 file changed, 87 insertions(+), 80 deletions(-)
diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c index fc41f05da2..6f2a83cc7c 100644 --- a/dlls/msvcrt/locale.c +++ b/dlls/msvcrt/locale.c @@ -910,8 +910,7 @@ static inline BOOL category_needs_update(int cat, int user_cat, return lcid!=locinfo->lc_handle[cat] || cp!=locinfo->lc_id[cat].wCodePage; }
-static MSVCRT_pthreadlocinfo create_locinfo(int category, - const char *locale, MSVCRT_pthreadlocinfo old_locinfo) +static MSVCRT___lc_time_data* create_time_data(LCID lcid) { static const DWORD time_data[] = { LOCALE_SABBREVDAYNAME7, LOCALE_SABBREVDAYNAME1, LOCALE_SABBREVDAYNAME2, @@ -930,11 +929,6 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, LOCALE_SSHORTDATE, LOCALE_SLONGDATE, LOCALE_STIMEFORMAT }; - static const char collate[] = "COLLATE="; - static const char ctype[] = "CTYPE="; - static const char monetary[] = "MONETARY="; - static const char numeric[] = "NUMERIC="; - static const char time[] = "TIME="; static const char cloc_short_date[] = "MM/dd/yy"; static const MSVCRT_wchar_t cloc_short_dateW[] = {'M','M','/','d','d','/','y','y',0}; static const char cloc_long_date[] = "dddd, MMMM dd, yyyy"; @@ -942,8 +936,91 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, static const char cloc_time[] = "HH:mm:ss"; static const MSVCRT_wchar_t cloc_timeW[] = {'H','H',':','m','m',':','s','s',0};
+ MSVCRT___lc_time_data *cur; + const DWORD flags = lcid ? 0 : LOCALE_NOUSEROVERRIDE; + const LCID lcid_tmp = lcid ? lcid : MAKELCID(LANG_ENGLISH, SORT_DEFAULT); + int i, ret, size; + + size = sizeof(MSVCRT___lc_time_data); + for(i=0; i<ARRAY_SIZE(time_data); i++) { + if(time_data[i]==LOCALE_SSHORTDATE && !lcid) { + size += sizeof(cloc_short_date) + sizeof(cloc_short_dateW); + }else if(time_data[i]==LOCALE_SLONGDATE && !lcid) { + size += sizeof(cloc_long_date) + sizeof(cloc_long_dateW); + }else { + ret = GetLocaleInfoA(lcid_tmp, time_data[i]|flags, NULL, 0); + if(!ret) + return NULL; + size += ret; + + ret = GetLocaleInfoW(lcid_tmp, time_data[i]|flags, NULL, 0); + if(!ret) + return NULL; + size += ret*sizeof(MSVCRT_wchar_t); + } + } +#if _MSVCR_VER >= 110 + size += LCIDToLocaleName(lcid, NULL, 0, 0)*sizeof(MSVCRT_wchar_t); +#endif + + cur = MSVCRT_malloc(size); + if(!cur) + return NULL; + + ret = 0; + for(i=0; i<ARRAY_SIZE(time_data); i++) { + cur->str.str[i] = &cur->data[ret]; + if(time_data[i]==LOCALE_SSHORTDATE && !lcid) { + memcpy(&cur->data[ret], cloc_short_date, sizeof(cloc_short_date)); + ret += sizeof(cloc_short_date); + }else if(time_data[i]==LOCALE_SLONGDATE && !lcid) { + memcpy(&cur->data[ret], cloc_long_date, sizeof(cloc_long_date)); + ret += sizeof(cloc_long_date); + }else if(time_data[i]==LOCALE_STIMEFORMAT && !lcid) { + memcpy(&cur->data[ret], cloc_time, sizeof(cloc_time)); + ret += sizeof(cloc_time); + }else { + ret += GetLocaleInfoA(lcid_tmp, time_data[i]|flags, + &cur->data[ret], size-ret); + } + } + for(i=0; i<ARRAY_SIZE(time_data); i++) { + cur->wstr.wstr[i] = (MSVCRT_wchar_t*)&cur->data[ret]; + if(time_data[i]==LOCALE_SSHORTDATE && !lcid) { + memcpy(&cur->data[ret], cloc_short_dateW, sizeof(cloc_short_dateW)); + ret += sizeof(cloc_short_dateW); + }else if(time_data[i]==LOCALE_SLONGDATE && !lcid) { + memcpy(&cur->data[ret], cloc_long_dateW, sizeof(cloc_long_dateW)); + ret += sizeof(cloc_long_dateW); + }else if(time_data[i]==LOCALE_STIMEFORMAT && !lcid) { + memcpy(&cur->data[ret], cloc_timeW, sizeof(cloc_timeW)); + ret += sizeof(cloc_timeW); + }else { + ret += GetLocaleInfoW(lcid_tmp, time_data[i]|flags, + (MSVCRT_wchar_t*)&cur->data[ret], size-ret)*sizeof(MSVCRT_wchar_t); + } + } +#if _MSVCR_VER >= 110 + cur->locname = (MSVCRT_wchar_t*)&cur->data[ret]; + LCIDToLocaleName(lcid, cur->locname, (size-ret)/sizeof(MSVCRT_wchar_t), 0); +#else + cur->lcid = lcid; +#endif + + return cur; +} + +static MSVCRT_pthreadlocinfo create_locinfo(int category, + const char *locale, MSVCRT_pthreadlocinfo old_locinfo) +{ + static const char collate[] = "COLLATE="; + static const char ctype[] = "CTYPE="; + static const char monetary[] = "MONETARY="; + static const char numeric[] = "NUMERIC="; + static const char time[] = "TIME="; + MSVCRT_pthreadlocinfo locinfo; - LCID lcid[6] = { 0 }, lcid_tmp; + LCID lcid[6] = { 0 }; unsigned short cp[6] = { 0 }; const char *locale_name[6] = { 0 }; int locale_len[6] = { 0 }; @@ -952,7 +1029,7 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, #if _MSVCR_VER >= 100 MSVCRT_wchar_t wbuf[256]; #endif - int i, ret, size; + int i;
TRACE("(%d %s)\n", category, locale);
@@ -1588,8 +1665,6 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, locinfo->lc_handle[MSVCRT_LC_TIME] = old_locinfo->lc_handle[MSVCRT_LC_TIME]; locinfo->lc_id[MSVCRT_LC_TIME].wCodePage = old_locinfo->lc_id[MSVCRT_LC_TIME].wCodePage; } else { - DWORD flags = lcid[MSVCRT_LC_TIME] ? 0 : LOCALE_NOUSEROVERRIDE; - if(lcid[MSVCRT_LC_TIME] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_TIME)) { if(!update_threadlocinfo_category(lcid[MSVCRT_LC_TIME], cp[MSVCRT_LC_TIME], locinfo, MSVCRT_LC_TIME)) { @@ -1604,79 +1679,11 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, } else locinfo->lc_category[MSVCRT_LC_TIME].locale = MSVCRT__strdup("C");
- size = sizeof(MSVCRT___lc_time_data); - lcid_tmp = lcid[MSVCRT_LC_TIME] ? lcid[MSVCRT_LC_TIME] : MAKELCID(LANG_ENGLISH, SORT_DEFAULT); - for(i=0; i<ARRAY_SIZE(time_data); i++) { - if(time_data[i]==LOCALE_SSHORTDATE && !lcid[MSVCRT_LC_TIME]) { - size += sizeof(cloc_short_date) + sizeof(cloc_short_dateW); - }else if(time_data[i]==LOCALE_SLONGDATE && !lcid[MSVCRT_LC_TIME]) { - size += sizeof(cloc_long_date) + sizeof(cloc_long_dateW); - }else { - ret = GetLocaleInfoA(lcid_tmp, time_data[i]|flags, NULL, 0); - if(!ret) { - free_locinfo(locinfo); - return NULL; - } - size += ret; - - ret = GetLocaleInfoW(lcid_tmp, time_data[i]|flags, NULL, 0); - if(!ret) { - free_locinfo(locinfo); - return NULL; - } - size += ret*sizeof(MSVCRT_wchar_t); - } - } -#if _MSVCR_VER >= 110 - size += LCIDToLocaleName(lcid[MSVCRT_LC_TIME], NULL, 0, 0)*sizeof(MSVCRT_wchar_t); -#endif - - locinfo->lc_time_curr = MSVCRT_malloc(size); + locinfo->lc_time_curr = create_time_data(lcid[MSVCRT_LC_TIME]); if(!locinfo->lc_time_curr) { free_locinfo(locinfo); return NULL; } - - ret = 0; - for(i=0; i<ARRAY_SIZE(time_data); i++) { - locinfo->lc_time_curr->str.str[i] = &locinfo->lc_time_curr->data[ret]; - if(time_data[i]==LOCALE_SSHORTDATE && !lcid[MSVCRT_LC_TIME]) { - memcpy(&locinfo->lc_time_curr->data[ret], cloc_short_date, sizeof(cloc_short_date)); - ret += sizeof(cloc_short_date); - }else if(time_data[i]==LOCALE_SLONGDATE && !lcid[MSVCRT_LC_TIME]) { - memcpy(&locinfo->lc_time_curr->data[ret], cloc_long_date, sizeof(cloc_long_date)); - ret += sizeof(cloc_long_date); - }else if(time_data[i]==LOCALE_STIMEFORMAT && !lcid[MSVCRT_LC_TIME]) { - memcpy(&locinfo->lc_time_curr->data[ret], cloc_time, sizeof(cloc_time)); - ret += sizeof(cloc_time); - }else { - ret += GetLocaleInfoA(lcid_tmp, time_data[i]|flags, - &locinfo->lc_time_curr->data[ret], size-ret); - } - } - for(i=0; i<ARRAY_SIZE(time_data); i++) { - locinfo->lc_time_curr->wstr.wstr[i] = (MSVCRT_wchar_t*)&locinfo->lc_time_curr->data[ret]; - if(time_data[i]==LOCALE_SSHORTDATE && !lcid[MSVCRT_LC_TIME]) { - memcpy(&locinfo->lc_time_curr->data[ret], cloc_short_dateW, sizeof(cloc_short_dateW)); - ret += sizeof(cloc_short_dateW); - }else if(time_data[i]==LOCALE_SLONGDATE && !lcid[MSVCRT_LC_TIME]) { - memcpy(&locinfo->lc_time_curr->data[ret], cloc_long_dateW, sizeof(cloc_long_dateW)); - ret += sizeof(cloc_long_dateW); - }else if(time_data[i]==LOCALE_STIMEFORMAT && !lcid[MSVCRT_LC_TIME]) { - memcpy(&locinfo->lc_time_curr->data[ret], cloc_timeW, sizeof(cloc_timeW)); - ret += sizeof(cloc_timeW); - }else { - ret += GetLocaleInfoW(lcid_tmp, time_data[i]|flags, - (MSVCRT_wchar_t*)&locinfo->lc_time_curr->data[ret], size-ret)*sizeof(MSVCRT_wchar_t); - } - } -#if _MSVCR_VER >= 110 - locinfo->lc_time_curr->locname = (MSVCRT_wchar_t*)&locinfo->lc_time_curr->data[ret]; - LCIDToLocaleName(lcid[MSVCRT_LC_TIME], locinfo->lc_time_curr->locname, - (size-ret)/sizeof(MSVCRT_wchar_t), 0); -#else - locinfo->lc_time_curr->lcid = lcid[MSVCRT_LC_TIME]; -#endif }
return locinfo;
Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/msvcrt/locale.c | 156 ++++++++++++++++++++++++++----------------- dlls/msvcrt/msvcrt.h | 1 + 2 files changed, 95 insertions(+), 62 deletions(-)
diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c index 6f2a83cc7c..2a5cc7fc02 100644 --- a/dlls/msvcrt/locale.c +++ b/dlls/msvcrt/locale.c @@ -53,6 +53,74 @@ BOOL initial_locale = TRUE; #define MSVCRT_LEADBYTE 0x8000 #define MSVCRT_C1_DEFINED 0x200
+static MSVCRT_wchar_t C_time_curr_wstr[43][20] = +{ + {'S','u','n',0}, {'M','o','n',0}, {'T','u','e',0}, {'W','e','d',0}, + {'T','h','u',0}, {'F','r','i',0}, {'S','a','t',0}, + {'S','u','n','d','a','y',0}, {'M','o','n','d','a','y',0}, + {'T','u','e','s','d','a','y',0}, {'W','e','d','n','e','s','d','a','y',0}, + {'T','h','u','r','s','d','a','y',0}, {'F','r','i','d','a','y',0}, + {'S','a','t','u','r','d','a','y',0}, + {'J','a','n',0}, {'F','e','b',0}, {'M','a','r',0}, {'A','p','r',0}, + {'M','a','y',0}, {'J','u','n',0}, {'J','u','l',0}, {'A','u','g',0}, + {'S','e','p',0}, {'O','c','t',0}, {'N','o','v',0}, {'D','e','c',0}, + {'J','a','n','u','a','r','y',0}, {'F','e','b','r','u','a','r','y',0}, + {'M','a','r','c','h',0}, {'A','p','r','i','l',0}, {'M','a','y',0}, + {'J','u','n','e',0}, {'J','u','l','y',0}, {'A','u','g','u','s','t',0}, + {'S','e','p','t','e','m','b','e','r',0}, {'O','c','t','o','b','e','r',0}, + {'N','o','v','e','m','b','e','r',0}, {'D','e','c','e','m','b','e','r',0}, + {'A','M',0}, {'P','M',0}, + {'M','M','/','d','d','/','y','y',0}, + {'d','d','d','d',',',' ','M','M','M','M',' ','d','d',',',' ','y','y','y','y',0}, + {'H','H',':','m','m',':','s','s',0} +}; + +static char C_time_curr_str[43][20] = +{ + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", + "January", "February", "March", "April", "May", "June", "July", + "August", "September", "October", "November", "December", + "AM", "PM", "MM/dd/yy", "dddd, MMMM dd, yyyy", "HH:mm:ss" +}; + +static MSVCRT_wchar_t C_time_curr_locname[] = {'e','n','-','U','S',0}; + +MSVCRT___lc_time_data C_time_curr = +{ + {{C_time_curr_str[0], C_time_curr_str[1], C_time_curr_str[2], C_time_curr_str[3], + C_time_curr_str[4], C_time_curr_str[5], C_time_curr_str[6], C_time_curr_str[7], + C_time_curr_str[8], C_time_curr_str[9], C_time_curr_str[10], C_time_curr_str[11], + C_time_curr_str[12], C_time_curr_str[13], C_time_curr_str[14], C_time_curr_str[15], + C_time_curr_str[16], C_time_curr_str[17], C_time_curr_str[18], C_time_curr_str[19], + C_time_curr_str[20], C_time_curr_str[21], C_time_curr_str[22], C_time_curr_str[23], + C_time_curr_str[24], C_time_curr_str[25], C_time_curr_str[26], C_time_curr_str[27], + C_time_curr_str[28], C_time_curr_str[29], C_time_curr_str[30], C_time_curr_str[31], + C_time_curr_str[32], C_time_curr_str[33], C_time_curr_str[34], C_time_curr_str[35], + C_time_curr_str[36], C_time_curr_str[37], C_time_curr_str[38], C_time_curr_str[39], + C_time_curr_str[40], C_time_curr_str[41], C_time_curr_str[42]}}, +#if _MSVCR_VER < 110 + MAKELCID(LANG_ENGLISH, SORT_DEFAULT), +#endif + {0, 0}, + {{C_time_curr_wstr[0], C_time_curr_wstr[1], C_time_curr_wstr[2], C_time_curr_wstr[3], + C_time_curr_wstr[4], C_time_curr_wstr[5], C_time_curr_wstr[6], C_time_curr_wstr[7], + C_time_curr_wstr[8], C_time_curr_wstr[9], C_time_curr_wstr[10], C_time_curr_wstr[11], + C_time_curr_wstr[12], C_time_curr_wstr[13], C_time_curr_wstr[14], C_time_curr_wstr[15], + C_time_curr_wstr[16], C_time_curr_wstr[17], C_time_curr_wstr[18], C_time_curr_wstr[19], + C_time_curr_wstr[20], C_time_curr_wstr[21], C_time_curr_wstr[22], C_time_curr_wstr[23], + C_time_curr_wstr[24], C_time_curr_wstr[25], C_time_curr_wstr[26], C_time_curr_wstr[27], + C_time_curr_wstr[28], C_time_curr_wstr[29], C_time_curr_wstr[30], C_time_curr_wstr[31], + C_time_curr_wstr[32], C_time_curr_wstr[33], C_time_curr_wstr[34], C_time_curr_wstr[35], + C_time_curr_wstr[36], C_time_curr_wstr[37], C_time_curr_wstr[38], C_time_curr_wstr[39], + C_time_curr_wstr[40], C_time_curr_wstr[41], C_time_curr_wstr[42]}}, +#if _MSVCR_VER >= 110 + C_time_curr_locname, +#endif + {} +}; + /* Friendly country strings & language names abbreviations. */ static const char * const _country_synonyms[] = { @@ -829,7 +897,8 @@ void free_locinfo(MSVCRT_pthreadlocinfo locinfo) MSVCRT_free(locinfo->pclmap); MSVCRT_free(locinfo->pcumap);
- MSVCRT_free(locinfo->lc_time_curr); + if(locinfo->lc_time_curr != &C_time_curr) + MSVCRT_free(locinfo->lc_time_curr);
MSVCRT_free(locinfo); } @@ -929,35 +998,21 @@ static MSVCRT___lc_time_data* create_time_data(LCID lcid) LOCALE_SSHORTDATE, LOCALE_SLONGDATE, LOCALE_STIMEFORMAT }; - static const char cloc_short_date[] = "MM/dd/yy"; - static const MSVCRT_wchar_t cloc_short_dateW[] = {'M','M','/','d','d','/','y','y',0}; - static const char cloc_long_date[] = "dddd, MMMM dd, yyyy"; - static const MSVCRT_wchar_t cloc_long_dateW[] = {'d','d','d','d',',',' ','M','M','M','M',' ','d','d',',',' ','y','y','y','y',0}; - static const char cloc_time[] = "HH:mm:ss"; - static const MSVCRT_wchar_t cloc_timeW[] = {'H','H',':','m','m',':','s','s',0};
MSVCRT___lc_time_data *cur; - const DWORD flags = lcid ? 0 : LOCALE_NOUSEROVERRIDE; - const LCID lcid_tmp = lcid ? lcid : MAKELCID(LANG_ENGLISH, SORT_DEFAULT); int i, ret, size;
size = sizeof(MSVCRT___lc_time_data); for(i=0; i<ARRAY_SIZE(time_data); i++) { - if(time_data[i]==LOCALE_SSHORTDATE && !lcid) { - size += sizeof(cloc_short_date) + sizeof(cloc_short_dateW); - }else if(time_data[i]==LOCALE_SLONGDATE && !lcid) { - size += sizeof(cloc_long_date) + sizeof(cloc_long_dateW); - }else { - ret = GetLocaleInfoA(lcid_tmp, time_data[i]|flags, NULL, 0); - if(!ret) - return NULL; - size += ret; + ret = GetLocaleInfoA(lcid, time_data[i], NULL, 0); + if(!ret) + return NULL; + size += ret;
- ret = GetLocaleInfoW(lcid_tmp, time_data[i]|flags, NULL, 0); - if(!ret) - return NULL; - size += ret*sizeof(MSVCRT_wchar_t); - } + ret = GetLocaleInfoW(lcid, time_data[i], NULL, 0); + if(!ret) + return NULL; + size += ret*sizeof(MSVCRT_wchar_t); } #if _MSVCR_VER >= 110 size += LCIDToLocaleName(lcid, NULL, 0, 0)*sizeof(MSVCRT_wchar_t); @@ -970,35 +1025,12 @@ static MSVCRT___lc_time_data* create_time_data(LCID lcid) ret = 0; for(i=0; i<ARRAY_SIZE(time_data); i++) { cur->str.str[i] = &cur->data[ret]; - if(time_data[i]==LOCALE_SSHORTDATE && !lcid) { - memcpy(&cur->data[ret], cloc_short_date, sizeof(cloc_short_date)); - ret += sizeof(cloc_short_date); - }else if(time_data[i]==LOCALE_SLONGDATE && !lcid) { - memcpy(&cur->data[ret], cloc_long_date, sizeof(cloc_long_date)); - ret += sizeof(cloc_long_date); - }else if(time_data[i]==LOCALE_STIMEFORMAT && !lcid) { - memcpy(&cur->data[ret], cloc_time, sizeof(cloc_time)); - ret += sizeof(cloc_time); - }else { - ret += GetLocaleInfoA(lcid_tmp, time_data[i]|flags, - &cur->data[ret], size-ret); - } + ret += GetLocaleInfoA(lcid, time_data[i], &cur->data[ret], size-ret); } for(i=0; i<ARRAY_SIZE(time_data); i++) { cur->wstr.wstr[i] = (MSVCRT_wchar_t*)&cur->data[ret]; - if(time_data[i]==LOCALE_SSHORTDATE && !lcid) { - memcpy(&cur->data[ret], cloc_short_dateW, sizeof(cloc_short_dateW)); - ret += sizeof(cloc_short_dateW); - }else if(time_data[i]==LOCALE_SLONGDATE && !lcid) { - memcpy(&cur->data[ret], cloc_long_dateW, sizeof(cloc_long_dateW)); - ret += sizeof(cloc_long_dateW); - }else if(time_data[i]==LOCALE_STIMEFORMAT && !lcid) { - memcpy(&cur->data[ret], cloc_timeW, sizeof(cloc_timeW)); - ret += sizeof(cloc_timeW); - }else { - ret += GetLocaleInfoW(lcid_tmp, time_data[i]|flags, - (MSVCRT_wchar_t*)&cur->data[ret], size-ret)*sizeof(MSVCRT_wchar_t); - } + ret += GetLocaleInfoW(lcid, time_data[i], + (MSVCRT_wchar_t*)&cur->data[ret], size-ret)*sizeof(MSVCRT_wchar_t); } #if _MSVCR_VER >= 110 cur->locname = (MSVCRT_wchar_t*)&cur->data[ret]; @@ -1664,26 +1696,26 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, lcid[MSVCRT_LC_TIME], cp[MSVCRT_LC_TIME])) { locinfo->lc_handle[MSVCRT_LC_TIME] = old_locinfo->lc_handle[MSVCRT_LC_TIME]; locinfo->lc_id[MSVCRT_LC_TIME].wCodePage = old_locinfo->lc_id[MSVCRT_LC_TIME].wCodePage; - } else { - if(lcid[MSVCRT_LC_TIME] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_TIME)) { - if(!update_threadlocinfo_category(lcid[MSVCRT_LC_TIME], - cp[MSVCRT_LC_TIME], locinfo, MSVCRT_LC_TIME)) { - free_locinfo(locinfo); - return NULL; - } + } else if(lcid[MSVCRT_LC_TIME] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_TIME)) { + if(!update_threadlocinfo_category(lcid[MSVCRT_LC_TIME], + cp[MSVCRT_LC_TIME], locinfo, MSVCRT_LC_TIME)) { + free_locinfo(locinfo); + return NULL; + }
- if(!set_lc_locale_name(locinfo, MSVCRT_LC_TIME)) { - free_locinfo(locinfo); - return NULL; - } - } else - locinfo->lc_category[MSVCRT_LC_TIME].locale = MSVCRT__strdup("C"); + if(!set_lc_locale_name(locinfo, MSVCRT_LC_TIME)) { + free_locinfo(locinfo); + return NULL; + }
locinfo->lc_time_curr = create_time_data(lcid[MSVCRT_LC_TIME]); if(!locinfo->lc_time_curr) { free_locinfo(locinfo); return NULL; } + } else { + locinfo->lc_category[MSVCRT_LC_TIME].locale = MSVCRT__strdup("C"); + locinfo->lc_time_curr = &C_time_curr; }
return locinfo; diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h index 4a7e6f4219..cd7def3c27 100644 --- a/dlls/msvcrt/msvcrt.h +++ b/dlls/msvcrt/msvcrt.h @@ -305,6 +305,7 @@ extern thread_data_t *msvcrt_get_thread_data(void) DECLSPEC_HIDDEN;
LCID MSVCRT_locale_to_LCID(const char*, unsigned short*, BOOL*) DECLSPEC_HIDDEN; extern MSVCRT__locale_t MSVCRT_locale DECLSPEC_HIDDEN; +extern MSVCRT___lc_time_data C_time_curr DECLSPEC_HIDDEN; extern unsigned int MSVCRT___lc_codepage; extern int MSVCRT___lc_collate_cp; extern WORD MSVCRT__ctype [257];
Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/msvcrt/time.c | 14 +++++++++++++- dlls/ucrtbase/tests/misc.c | 8 ++++---- 2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c index ef4f228554..4b8ad48c09 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -1234,6 +1234,18 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
switch(*format) { case 'c': +#if _MSVCR_VER>=140 + if(time_data == &C_time_curr && !alternate) + { + static const WCHAR datetime_format[] = + { '%','a',' ','%','b',' ','%','e',' ','%','T',' ','%','Y',0 }; + tmp = strftime_impl(str+ret, max-ret, datetime_format, mstm, time_data, loc); + if(!tmp) + return 0; + ret += tmp; + break; + } +#endif if(!strftime_format(str, &ret, max, mstm, time_data, alternate ? STRFTIME_TD(time_data, date) : STRFTIME_TD(time_data, short_date))) return 0; @@ -1387,7 +1399,7 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max, break; #if _MSVCR_VER>=140 case 'r': - if(time_data == MSVCRT_locale->locinfo->lc_time_curr) + if(time_data == &C_time_curr) { if(!MSVCRT_CHECK_PMT(mstm->tm_hour>=0 && mstm->tm_hour<=23)) goto einval_error; diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index d6fdf271e0..28832e9997 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -1004,8 +1004,8 @@ static void test_strftime(void) {"%y", "00", { 0, 0, 0, 0, 0, -1900, 0, 0, 0 }}, {"%y", "99", { 0, 0, 0, 0, 0, 8099, 0, 0, 0 }}, {"%y", "", { 0, 0, 0, 0, 0, 8100, 0, 0, 0 }}, - {"%c", "Thu Jan 1 00:00:00 1970", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }, TRUE, TRUE}, - {"%c", "Thu Feb 30 00:00:00 1970", { 0, 0, 0, 30, 1, 70, 4, 0, 0 }, TRUE, TRUE}, + {"%c", "Thu Jan 1 00:00:00 1970", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, + {"%c", "Thu Feb 30 00:00:00 1970", { 0, 0, 0, 30, 1, 70, 4, 0, 0 }}, {"%#c", "Thursday, January 01, 1970 00:00:00", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, {"%#c", "Thursday, February 30, 1970 00:00:00", { 0, 0, 0, 30, 1, 70, 4, 0, 0 }}, {"%x", "01/01/70", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, @@ -1197,8 +1197,8 @@ static void test_strftime(void) ok(ret == 19, "ret = %d\n", ret); ok(!strcmp(buf, "01/01/1970 00:00:00"), "buf = "%s", expected "%s"\n", buf, "01/01/1970 00:00:00"); ret = p_strftime(buf, sizeof(buf), "%r", &epoch); - todo_wine ok(ret == 8, "ret = %d\n", ret); - todo_wine ok(!strcmp(buf, "00:00:00"), "buf = "%s", expected "%s"\n", buf, "00:00:00"); + ok(ret == 8, "ret = %d\n", ret); + ok(!strcmp(buf, "00:00:00"), "buf = "%s", expected "%s"\n", buf, "00:00:00"); p_setlocale(LC_ALL, "C"); }