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..606e74b524 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"); @@ -1135,6 +1138,8 @@ static void test_strftime(void) struct tm tm_yweek = { 0, 0, 0, 1, 0, 70, 0, 0, 0 }; char buf[256]; int i, ret=0; + char expected[] = "01/01/1970 00:00:00"; + const char *locale;
for (i=0; i<ARRAY_SIZE(tests); i++) { @@ -1185,6 +1190,16 @@ static void test_strftime(void) i, j, buf, tests_yweek[i].ret[j]); } } + + locale = p_setlocale(LC_ALL, NULL); + p_setlocale(LC_ALL, "fr-FR"); + ret = p_strftime(buf, sizeof(buf), "%c", &epoch); + ok(ret == strlen(expected), "ret = %d\n", ret); + ok(!strcmp(buf, expected), "buf = "%s", expected "%s"\n", buf, expected); + ret = p_strftime(buf, sizeof(buf), "%x %r", &epoch); + todo_wine ok(ret == strlen(expected), "ret = %d\n", ret); + todo_wine ok(!strcmp(buf, expected), "buf = "%s", expected "%s"\n", buf, expected); + p_setlocale(LC_ALL, locale); }
static LONG* get_failures_counter(HANDLE *map)
Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/msvcrt/locale.c | 328 +++++++++++++++---------------------------- 1 file changed, 112 insertions(+), 216 deletions(-)
diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c index fc41f05da2..f472432144 100644 --- a/dlls/msvcrt/locale.c +++ b/dlls/msvcrt/locale.c @@ -1048,25 +1048,19 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, locinfo->refcount = 1;
locinfo->lconv = MSVCRT_malloc(sizeof(struct MSVCRT_lconv)); - if(!locinfo->lconv) { - free_locinfo(locinfo); - return NULL; - } + if(!locinfo->lconv) + goto failed; memset(locinfo->lconv, 0, sizeof(struct MSVCRT_lconv));
locinfo->pclmap = MSVCRT_malloc(sizeof(char[256])); locinfo->pcumap = MSVCRT_malloc(sizeof(char[256])); - if(!locinfo->pclmap || !locinfo->pcumap) { - free_locinfo(locinfo); - return NULL; - } + if(!locinfo->pclmap || !locinfo->pcumap) + goto failed;
if(locale_name[MSVCRT_LC_COLLATE] && !init_category_name(locale_name[MSVCRT_LC_COLLATE], - locale_len[MSVCRT_LC_COLLATE], locinfo, MSVCRT_LC_COLLATE)) { - free_locinfo(locinfo); - return NULL; - } + locale_len[MSVCRT_LC_COLLATE], locinfo, MSVCRT_LC_COLLATE)) + goto failed;
if(!category_needs_update(MSVCRT_LC_COLLATE, category, old_locinfo, lcid[MSVCRT_LC_COLLATE], cp[MSVCRT_LC_COLLATE])) { @@ -1074,26 +1068,20 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, locinfo->lc_id[MSVCRT_LC_COLLATE].wCodePage = old_locinfo->lc_id[MSVCRT_LC_COLLATE].wCodePage; } else if(lcid[MSVCRT_LC_COLLATE] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_COLLATE)) { if(!update_threadlocinfo_category(lcid[MSVCRT_LC_COLLATE], - cp[MSVCRT_LC_COLLATE], locinfo, MSVCRT_LC_COLLATE)) { - free_locinfo(locinfo); - return NULL; - } + cp[MSVCRT_LC_COLLATE], locinfo, MSVCRT_LC_COLLATE)) + goto failed;
locinfo->lc_collate_cp = locinfo->lc_id[MSVCRT_LC_COLLATE].wCodePage;
- if(!set_lc_locale_name(locinfo, MSVCRT_LC_COLLATE)) { - free_locinfo(locinfo); - return NULL; - } + if(!set_lc_locale_name(locinfo, MSVCRT_LC_COLLATE)) + goto failed; } else locinfo->lc_category[MSVCRT_LC_COLLATE].locale = MSVCRT__strdup("C");
if(locale_name[MSVCRT_LC_CTYPE] && !init_category_name(locale_name[MSVCRT_LC_CTYPE], - locale_len[MSVCRT_LC_CTYPE], locinfo, MSVCRT_LC_CTYPE)) { - free_locinfo(locinfo); - return NULL; - } + locale_len[MSVCRT_LC_CTYPE], locinfo, MSVCRT_LC_CTYPE)) + goto failed;
if(!category_needs_update(MSVCRT_LC_CTYPE, category, old_locinfo, lcid[MSVCRT_LC_CTYPE], cp[MSVCRT_LC_CTYPE])) { @@ -1104,25 +1092,19 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, int j;
if(!update_threadlocinfo_category(lcid[MSVCRT_LC_CTYPE], - cp[MSVCRT_LC_CTYPE], locinfo, MSVCRT_LC_CTYPE)) { - free_locinfo(locinfo); - return NULL; - } + cp[MSVCRT_LC_CTYPE], locinfo, MSVCRT_LC_CTYPE)) + goto failed;
locinfo->lc_codepage = locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage; locinfo->lc_clike = 1; - if(!GetCPInfo(locinfo->lc_codepage, &cp_info)) { - free_locinfo(locinfo); - return NULL; - } + if(!GetCPInfo(locinfo->lc_codepage, &cp_info)) + goto failed; locinfo->mb_cur_max = cp_info.MaxCharSize;
locinfo->ctype1_refcount = MSVCRT_malloc(sizeof(int)); locinfo->ctype1 = MSVCRT_malloc(sizeof(short[257])); - if(!locinfo->ctype1_refcount || !locinfo->ctype1) { - free_locinfo(locinfo); - return NULL; - } + if(!locinfo->ctype1_refcount || !locinfo->ctype1) + goto failed;
*locinfo->ctype1_refcount = 1; locinfo->ctype1[0] = 0; @@ -1143,10 +1125,8 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, for(j=cp_info.LeadByte[i]; j<=cp_info.LeadByte[i+1]; j++) locinfo->ctype1[j+1] |= MSVCRT__LEADBYTE;
- if(!set_lc_locale_name(locinfo, MSVCRT_LC_CTYPE)) { - free_locinfo(locinfo); - return NULL; - } + if(!set_lc_locale_name(locinfo, MSVCRT_LC_CTYPE)) + goto failed;
for(i=0; i<256; i++) { if(locinfo->pctype[i] & MSVCRT__LEADBYTE) @@ -1180,10 +1160,8 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category,
if(locale_name[MSVCRT_LC_MONETARY] && !init_category_name(locale_name[MSVCRT_LC_MONETARY], - locale_len[MSVCRT_LC_MONETARY], locinfo, MSVCRT_LC_MONETARY)) { - free_locinfo(locinfo); - return NULL; - } + locale_len[MSVCRT_LC_MONETARY], locinfo, MSVCRT_LC_MONETARY)) + goto failed;
if(!category_needs_update(MSVCRT_LC_MONETARY, category, old_locinfo, lcid[MSVCRT_LC_MONETARY], cp[MSVCRT_LC_MONETARY])) { @@ -1191,17 +1169,13 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, locinfo->lc_id[MSVCRT_LC_MONETARY].wCodePage = old_locinfo->lc_id[MSVCRT_LC_MONETARY].wCodePage; } else if(lcid[MSVCRT_LC_MONETARY] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_MONETARY)) { if(!update_threadlocinfo_category(lcid[MSVCRT_LC_MONETARY], - cp[MSVCRT_LC_MONETARY], locinfo, MSVCRT_LC_MONETARY)) { - free_locinfo(locinfo); - return NULL; - } + cp[MSVCRT_LC_MONETARY], locinfo, MSVCRT_LC_MONETARY)) + goto failed;
locinfo->lconv_intl_refcount = MSVCRT_malloc(sizeof(int)); locinfo->lconv_mon_refcount = MSVCRT_malloc(sizeof(int)); - if(!locinfo->lconv_intl_refcount || !locinfo->lconv_mon_refcount) { - free_locinfo(locinfo); - return NULL; - } + if(!locinfo->lconv_intl_refcount || !locinfo->lconv_mon_refcount) + goto failed;
*locinfo->lconv_intl_refcount = 1; *locinfo->lconv_mon_refcount = 1; @@ -1210,37 +1184,29 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, |LOCALE_NOUSEROVERRIDE, buf, 256); if(i && (locinfo->lconv->int_curr_symbol = MSVCRT_malloc(i))) memcpy(locinfo->lconv->int_curr_symbol, buf, i); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SCURRENCY |LOCALE_NOUSEROVERRIDE, buf, 256); if(i && (locinfo->lconv->currency_symbol = MSVCRT_malloc(i))) memcpy(locinfo->lconv->currency_symbol, buf, i); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONDECIMALSEP |LOCALE_NOUSEROVERRIDE, buf, 256); if(i && (locinfo->lconv->mon_decimal_point = MSVCRT_malloc(i))) memcpy(locinfo->lconv->mon_decimal_point, buf, i); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONTHOUSANDSEP |LOCALE_NOUSEROVERRIDE, buf, 256); if(i && (locinfo->lconv->mon_thousands_sep = MSVCRT_malloc(i))) memcpy(locinfo->lconv->mon_thousands_sep, buf, i); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONGROUPING |LOCALE_NOUSEROVERRIDE, buf, 256); @@ -1252,153 +1218,117 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, locinfo->lconv->mon_grouping[i/2] = buf[i]-'0'; if(buf[i] != '0') locinfo->lconv->mon_grouping[i/2+1] = 127; - } else { - free_locinfo(locinfo); - return NULL; - } + } else + goto failed;
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SPOSITIVESIGN |LOCALE_NOUSEROVERRIDE, buf, 256); if(i && (locinfo->lconv->positive_sign = MSVCRT_malloc(i))) memcpy(locinfo->lconv->positive_sign, buf, i); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SNEGATIVESIGN |LOCALE_NOUSEROVERRIDE, buf, 256); if(i && (locinfo->lconv->negative_sign = MSVCRT_malloc(i))) memcpy(locinfo->lconv->negative_sign, buf, i); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IINTLCURRDIGITS |LOCALE_NOUSEROVERRIDE, buf, 256)) locinfo->lconv->int_frac_digits = atoi(buf); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_ICURRDIGITS |LOCALE_NOUSEROVERRIDE, buf, 256)) locinfo->lconv->frac_digits = atoi(buf); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSYMPRECEDES |LOCALE_NOUSEROVERRIDE, buf, 256)) locinfo->lconv->p_cs_precedes = atoi(buf); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSEPBYSPACE |LOCALE_NOUSEROVERRIDE, buf, 256)) locinfo->lconv->p_sep_by_space = atoi(buf); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSYMPRECEDES |LOCALE_NOUSEROVERRIDE, buf, 256)) locinfo->lconv->n_cs_precedes = atoi(buf); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSEPBYSPACE |LOCALE_NOUSEROVERRIDE, buf, 256)) locinfo->lconv->n_sep_by_space = atoi(buf); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSIGNPOSN |LOCALE_NOUSEROVERRIDE, buf, 256)) locinfo->lconv->p_sign_posn = atoi(buf); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSIGNPOSN |LOCALE_NOUSEROVERRIDE, buf, 256)) locinfo->lconv->n_sign_posn = atoi(buf); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
#if _MSVCR_VER >= 100 i = GetLocaleInfoW(lcid[MSVCRT_LC_MONETARY], LOCALE_SINTLSYMBOL |LOCALE_NOUSEROVERRIDE, wbuf, 256); if(i && (locinfo->lconv->_W_int_curr_symbol = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t)))) memcpy(locinfo->lconv->_W_int_curr_symbol, wbuf, i * sizeof(MSVCRT_wchar_t)); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
i = GetLocaleInfoW(lcid[MSVCRT_LC_MONETARY], LOCALE_SCURRENCY |LOCALE_NOUSEROVERRIDE, wbuf, 256); if(i && (locinfo->lconv->_W_currency_symbol = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t)))) memcpy(locinfo->lconv->_W_currency_symbol, wbuf, i * sizeof(MSVCRT_wchar_t)); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
i = GetLocaleInfoW(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONDECIMALSEP |LOCALE_NOUSEROVERRIDE, wbuf, 256); if(i && (locinfo->lconv->_W_mon_decimal_point = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t)))) memcpy(locinfo->lconv->_W_mon_decimal_point, wbuf, i * sizeof(MSVCRT_wchar_t)); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
i = GetLocaleInfoW(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONTHOUSANDSEP |LOCALE_NOUSEROVERRIDE, wbuf, 256); if(i && (locinfo->lconv->_W_mon_thousands_sep = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t)))) memcpy(locinfo->lconv->_W_mon_thousands_sep, wbuf, i * sizeof(MSVCRT_wchar_t)); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
i = GetLocaleInfoW(lcid[MSVCRT_LC_MONETARY], LOCALE_SPOSITIVESIGN |LOCALE_NOUSEROVERRIDE, wbuf, 256); if(i && (locinfo->lconv->_W_positive_sign = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t)))) memcpy(locinfo->lconv->_W_positive_sign, wbuf, i * sizeof(MSVCRT_wchar_t)); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
i = GetLocaleInfoW(lcid[MSVCRT_LC_MONETARY], LOCALE_SNEGATIVESIGN |LOCALE_NOUSEROVERRIDE, wbuf, 256); if(i && (locinfo->lconv->_W_negative_sign = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t)))) memcpy(locinfo->lconv->_W_negative_sign, wbuf, i * sizeof(MSVCRT_wchar_t)); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed; #endif
- if(!set_lc_locale_name(locinfo, MSVCRT_LC_MONETARY)) { - free_locinfo(locinfo); - return NULL; - } + if(!set_lc_locale_name(locinfo, MSVCRT_LC_MONETARY)) + goto failed; } else { locinfo->lconv->int_curr_symbol = MSVCRT_malloc(sizeof(char)); locinfo->lconv->currency_symbol = MSVCRT_malloc(sizeof(char)); @@ -1411,10 +1341,8 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, if(!locinfo->lconv->int_curr_symbol || !locinfo->lconv->currency_symbol || !locinfo->lconv->mon_decimal_point || !locinfo->lconv->mon_thousands_sep || !locinfo->lconv->mon_grouping || !locinfo->lconv->positive_sign - || !locinfo->lconv->negative_sign) { - free_locinfo(locinfo); - return NULL; - } + || !locinfo->lconv->negative_sign) + goto failed;
locinfo->lconv->int_curr_symbol[0] = '\0'; locinfo->lconv->currency_symbol[0] = '\0'; @@ -1442,10 +1370,8 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category,
if(!locinfo->lconv->_W_int_curr_symbol || !locinfo->lconv->_W_currency_symbol || !locinfo->lconv->_W_mon_decimal_point || !locinfo->lconv->_W_mon_thousands_sep - || !locinfo->lconv->positive_sign || !locinfo->lconv->negative_sign) { - free_locinfo(locinfo); - return NULL; - } + || !locinfo->lconv->positive_sign || !locinfo->lconv->negative_sign) + goto failed;
locinfo->lconv->_W_int_curr_symbol[0] = '\0'; locinfo->lconv->_W_currency_symbol[0] = '\0'; @@ -1460,10 +1386,8 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category,
if(locale_name[MSVCRT_LC_NUMERIC] && !init_category_name(locale_name[MSVCRT_LC_NUMERIC], - locale_len[MSVCRT_LC_NUMERIC], locinfo, MSVCRT_LC_NUMERIC)) { - free_locinfo(locinfo); - return NULL; - } + locale_len[MSVCRT_LC_NUMERIC], locinfo, MSVCRT_LC_NUMERIC)) + goto failed;
if(!category_needs_update(MSVCRT_LC_NUMERIC, category, old_locinfo, lcid[MSVCRT_LC_NUMERIC], cp[MSVCRT_LC_NUMERIC])) { @@ -1471,18 +1395,14 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, locinfo->lc_id[MSVCRT_LC_NUMERIC].wCodePage = old_locinfo->lc_id[MSVCRT_LC_NUMERIC].wCodePage; } else if(lcid[MSVCRT_LC_NUMERIC] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_NUMERIC)) { if(!update_threadlocinfo_category(lcid[MSVCRT_LC_NUMERIC], - cp[MSVCRT_LC_NUMERIC], locinfo, MSVCRT_LC_NUMERIC)) { - free_locinfo(locinfo); - return NULL; - } + cp[MSVCRT_LC_NUMERIC], locinfo, MSVCRT_LC_NUMERIC)) + goto failed;
if(!locinfo->lconv_intl_refcount) locinfo->lconv_intl_refcount = MSVCRT_malloc(sizeof(int)); locinfo->lconv_num_refcount = MSVCRT_malloc(sizeof(int)); - if(!locinfo->lconv_intl_refcount || !locinfo->lconv_num_refcount) { - free_locinfo(locinfo); - return NULL; - } + if(!locinfo->lconv_intl_refcount || !locinfo->lconv_num_refcount) + goto failed;
*locinfo->lconv_intl_refcount = 1; *locinfo->lconv_num_refcount = 1; @@ -1491,19 +1411,15 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, |LOCALE_NOUSEROVERRIDE, buf, 256); if(i && (locinfo->lconv->decimal_point = MSVCRT_malloc(i))) memcpy(locinfo->lconv->decimal_point, buf, i); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_STHOUSAND |LOCALE_NOUSEROVERRIDE, buf, 256); if(i && (locinfo->lconv->thousands_sep = MSVCRT_malloc(i))) memcpy(locinfo->lconv->thousands_sep, buf, i); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_SGROUPING |LOCALE_NOUSEROVERRIDE, buf, 256); @@ -1515,44 +1431,34 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, locinfo->lconv->grouping[i/2] = buf[i]-'0'; if(buf[i] != '0') locinfo->lconv->grouping[i/2+1] = 127; - } else { - free_locinfo(locinfo); - return NULL; - } + } else + goto failed;
#if _MSVCR_VER >= 100 i = GetLocaleInfoW(lcid[MSVCRT_LC_NUMERIC], LOCALE_SDECIMAL |LOCALE_NOUSEROVERRIDE, wbuf, 256); if(i && (locinfo->lconv->_W_decimal_point = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t)))) memcpy(locinfo->lconv->_W_decimal_point, wbuf, i * sizeof(MSVCRT_wchar_t)); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed;
i = GetLocaleInfoW(lcid[MSVCRT_LC_NUMERIC], LOCALE_STHOUSAND |LOCALE_NOUSEROVERRIDE, wbuf, 256); if(i && (locinfo->lconv->_W_thousands_sep = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t)))) memcpy(locinfo->lconv->_W_thousands_sep, wbuf, i * sizeof(MSVCRT_wchar_t)); - else { - free_locinfo(locinfo); - return NULL; - } + else + goto failed; #endif
- if(!set_lc_locale_name(locinfo, MSVCRT_LC_NUMERIC)) { - free_locinfo(locinfo); - return NULL; - } + if(!set_lc_locale_name(locinfo, MSVCRT_LC_NUMERIC)) + goto failed; } else { locinfo->lconv->decimal_point = MSVCRT_malloc(sizeof(char[2])); locinfo->lconv->thousands_sep = MSVCRT_malloc(sizeof(char)); locinfo->lconv->grouping = MSVCRT_malloc(sizeof(char)); if(!locinfo->lconv->decimal_point || !locinfo->lconv->thousands_sep - || !locinfo->lconv->grouping) { - free_locinfo(locinfo); - return NULL; - } + || !locinfo->lconv->grouping) + goto failed;
locinfo->lconv->decimal_point[0] = '.'; locinfo->lconv->decimal_point[1] = '\0'; @@ -1563,10 +1469,8 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, locinfo->lconv->_W_decimal_point = MSVCRT_malloc(sizeof(MSVCRT_wchar_t[2])); locinfo->lconv->_W_thousands_sep = MSVCRT_malloc(sizeof(MSVCRT_wchar_t));
- if(!locinfo->lconv->_W_decimal_point || !locinfo->lconv->_W_thousands_sep) { - free_locinfo(locinfo); - return NULL; - } + if(!locinfo->lconv->_W_decimal_point || !locinfo->lconv->_W_thousands_sep) + goto failed;
locinfo->lconv->_W_decimal_point[0] = '.'; locinfo->lconv->_W_decimal_point[1] = '\0'; @@ -1578,10 +1482,8 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category,
if(locale_name[MSVCRT_LC_TIME] && !init_category_name(locale_name[MSVCRT_LC_TIME], - locale_len[MSVCRT_LC_TIME], locinfo, MSVCRT_LC_TIME)) { - free_locinfo(locinfo); - return NULL; - } + locale_len[MSVCRT_LC_TIME], locinfo, MSVCRT_LC_TIME)) + goto failed;
if(!category_needs_update(MSVCRT_LC_TIME, category, old_locinfo, lcid[MSVCRT_LC_TIME], cp[MSVCRT_LC_TIME])) { @@ -1592,15 +1494,11 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category,
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; - } + cp[MSVCRT_LC_TIME], locinfo, MSVCRT_LC_TIME)) + goto failed;
- if(!set_lc_locale_name(locinfo, MSVCRT_LC_TIME)) { - free_locinfo(locinfo); - return NULL; - } + if(!set_lc_locale_name(locinfo, MSVCRT_LC_TIME)) + goto failed; } else locinfo->lc_category[MSVCRT_LC_TIME].locale = MSVCRT__strdup("C");
@@ -1613,17 +1511,13 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, 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; - } + if(!ret) + goto failed; size += ret;
ret = GetLocaleInfoW(lcid_tmp, time_data[i]|flags, NULL, 0); - if(!ret) { - free_locinfo(locinfo); - return NULL; - } + if(!ret) + goto failed; size += ret*sizeof(MSVCRT_wchar_t); } } @@ -1632,10 +1526,8 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, #endif
locinfo->lc_time_curr = MSVCRT_malloc(size); - if(!locinfo->lc_time_curr) { - free_locinfo(locinfo); - return NULL; - } + if(!locinfo->lc_time_curr) + goto failed;
ret = 0; for(i=0; i<ARRAY_SIZE(time_data); i++) { @@ -1680,6 +1572,10 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, }
return locinfo; + +failed: + free_locinfo(locinfo); + return NULL; }
/*********************************************************************
Hi Jeff,
On 12/2/19 6:52 PM, Jeff Smith wrote:
- if(!locinfo->lconv) {
free_locinfo(locinfo);
return NULL;
- }
- if(!locinfo->lconv)
goto failed;
I'm not sure if it's an improvement. I think I would prefer the code to stay as it is.
Thanks, Piotr
Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/msvcrt/locale.c | 164 +++++++++++++++++++++++-------------------- 1 file changed, 88 insertions(+), 76 deletions(-)
diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c index f472432144..5a8d99493e 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,92 @@ 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 +1030,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);
@@ -1490,8 +1568,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)) @@ -1502,73 +1578,9 @@ 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) - goto failed; - size += ret; - - ret = GetLocaleInfoW(lcid_tmp, time_data[i]|flags, NULL, 0); - if(!ret) - goto failed; - 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) goto failed; - - 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 | 23 +++++++++++++---------- dlls/msvcrt/msvcrt.h | 1 + 2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c index 5a8d99493e..277e7802af 100644 --- a/dlls/msvcrt/locale.c +++ b/dlls/msvcrt/locale.c @@ -42,6 +42,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt); #define MAX_ELEM_LEN 64 /* Max length of country/language/CP string */ #define MAX_LOCALE_LENGTH 256 MSVCRT__locale_t MSVCRT_locale = NULL; +MSVCRT___lc_time_data *MSVCRT_time_curr = NULL; unsigned short *MSVCRT__pctype = NULL; unsigned int MSVCRT___lc_codepage = 0; int MSVCRT___lc_collate_cp = 0; @@ -829,7 +830,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 != MSVCRT_time_curr) + MSVCRT_free(locinfo->lc_time_curr);
MSVCRT_free(locinfo); } @@ -1567,20 +1569,20 @@ 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)) - goto failed; + } 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)) + goto failed;
- if(!set_lc_locale_name(locinfo, MSVCRT_LC_TIME)) - goto failed; - } else - locinfo->lc_category[MSVCRT_LC_TIME].locale = MSVCRT__strdup("C"); + if(!set_lc_locale_name(locinfo, MSVCRT_LC_TIME)) + goto failed;
locinfo->lc_time_curr = create_time_data(lcid[MSVCRT_LC_TIME]); if(!locinfo->lc_time_curr) goto failed; + } else { + locinfo->lc_category[MSVCRT_LC_TIME].locale = MSVCRT__strdup("C"); + locinfo->lc_time_curr = MSVCRT_time_curr; }
return locinfo; @@ -1962,6 +1964,7 @@ BOOL msvcrt_init_locale(void) { int i;
+ MSVCRT_time_curr = create_time_data(0); _lock_locales(); MSVCRT_locale = MSVCRT__create_locale(0, "C"); _unlock_locales(); diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h index 4a7e6f4219..445c28178a 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 *MSVCRT_time_curr DECLSPEC_HIDDEN; extern unsigned int MSVCRT___lc_codepage; extern int MSVCRT___lc_collate_cp; extern WORD MSVCRT__ctype [257];
Hi Jeff,
Could you please rename the MSVCRT_time_curr to something like time_data_c so the name shows it's for C locale?
It also needs to be freed on dll unload. On the other hand it may better to initialize it statically.
Thanks, Piotr
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..885166e638 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 == MSVCRT_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 == MSVCRT_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 606e74b524..51620dd0f2 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 == strlen(expected), "ret = %d\n", ret); ok(!strcmp(buf, expected), "buf = "%s", expected "%s"\n", buf, expected); ret = p_strftime(buf, sizeof(buf), "%x %r", &epoch); - todo_wine ok(ret == strlen(expected), "ret = %d\n", ret); - todo_wine ok(!strcmp(buf, expected), "buf = "%s", expected "%s"\n", buf, expected); + ok(ret == strlen(expected), "ret = %d\n", ret); + ok(!strcmp(buf, expected), "buf = "%s", expected "%s"\n", buf, expected); p_setlocale(LC_ALL, locale); }
Hi Jeff,
On 12/2/19 6:52 PM, Jeff Smith wrote:
- locale = p_setlocale(LC_ALL, NULL);
- p_setlocale(LC_ALL, "fr-FR");
setlocale may fail if the system is not supporting given locale. Please skip the test in this case.
- ret = p_strftime(buf, sizeof(buf), "%c", &epoch);
- ok(ret == strlen(expected), "ret = %d\n", ret);
- ok(!strcmp(buf, expected), "buf = "%s", expected "%s"\n", buf, expected);
- ret = p_strftime(buf, sizeof(buf), "%x %r", &epoch);
- todo_wine ok(ret == strlen(expected), "ret = %d\n", ret);
- todo_wine ok(!strcmp(buf, expected), "buf = "%s", expected "%s"\n", buf, expected);
Please change it to: ok(ret == strlen(buf), "ret = %d\n", ret); todo_wine ok(!strcmp(buf, "01/01/1970 00:00:00"), ...); It makes the expected variable not needed. I think the test is easier to read this way.
- p_setlocale(LC_ALL, locale);
Please restore C locale after the test (there's no need to store previous locale).
Thanks, Piotr