From 8909dff72139d2f0514a7bb83c6bf5c2959c4101 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sat, 31 Dec 2016 18:45:00 -0800 Subject: Always use the Windows time zone code on Windows. We *have* to use the Windows code on Windows for the reasons given in the comment. However, some versions of Visual Studio have a time.h that CMake thinks defines tzname[] (which the header will do under some circumstances), so HAVE_TZNAME gets defined on Windows. We check for Windows *before* checking for HAVE_TZNAME - or HAVE_STRUCT_TM_TM_ZONE. Bug: 11785 Change-Id: I61360daf08203dbd9d109a87c05727b4dbecea66 Reviewed-on: https://code.wireshark.org/review/19483 Petri-Dish: Guy Harris Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris --- epan/to_str.c | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'epan') diff --git a/epan/to_str.c b/epan/to_str.c index dc5d343e03..5ebb969a5f 100644 --- a/epan/to_str.c +++ b/epan/to_str.c @@ -384,16 +384,7 @@ static const char mon_names[12][4] = { static const gchar * get_zonename(struct tm *tmp) { -#if defined(HAVE_STRUCT_TM_TM_ZONE) - return tmp->tm_zone; -#else - if ((tmp->tm_isdst != 0) && (tmp->tm_isdst != 1)) { - return "???"; - } -# if defined(HAVE_TZNAME) - return tzname[tmp->tm_isdst]; - -# elif defined(_WIN32) +#if defined(_WIN32) /* Windows C Runtime: */ /* _tzname is encoded using the "system default ansi code page" */ /* ("which is not necessarily the same as the C library locale"). */ @@ -411,26 +402,39 @@ get_zonename(struct tm *tmp) /* on a "Japanese version of Windows XP" when trying to copy */ /* the date/time string (containing a copy of _tz_name) to the */ /* clipboard). */ + static char *ws_tzname[2] = {NULL, NULL}; - { - static char *ws_tzname[2] = {NULL, NULL}; - - /* The g_malloc'd value returned from g_locale_to_utf8() is */ - /* cached for all further use so there's no need to ever */ - /* g_free() that value. */ + /* The g_malloc'd value returned from g_locale_to_utf8() is */ + /* cached for all further use so there's no need to ever */ + /* g_free() that value. */ + if (ws_tzname[tmp->tm_isdst] == NULL) { + ws_tzname[tmp->tm_isdst] = g_locale_to_utf8(_tzname[tmp->tm_isdst], -1, NULL, NULL, NULL); if (ws_tzname[tmp->tm_isdst] == NULL) { - ws_tzname[tmp->tm_isdst] = g_locale_to_utf8(_tzname[tmp->tm_isdst], -1, NULL, NULL, NULL); - if (ws_tzname[tmp->tm_isdst] == NULL) { - ws_tzname[tmp->tm_isdst] = "???"; - } + ws_tzname[tmp->tm_isdst] = "???"; } - return ws_tzname[tmp->tm_isdst]; } -# else + return ws_tzname[tmp->tm_isdst]; +#else + /* + * UN*X. + * + * If we have tm_zone in struct tm, use that. + * Otherwise, if we have tzname[], use it, otherwise just + * say "we don't know. + */ +# if defined(HAVE_STRUCT_TM_TM_ZONE) + return tmp->tm_zone; +# else /* HAVE_STRUCT_TM_TM_ZONE */ + if ((tmp->tm_isdst != 0) && (tmp->tm_isdst != 1)) { + return "???"; + } +# if !defined(HAVE_TZNAME) + return tzname[tmp->tm_isdst]; +# else return tmp->tm_isdst ? "?DT" : "?ST"; - -# endif -#endif +# endif /* HAVE_TZNAME */ +# endif /* HAVE_STRUCT_TM_TM_ZONE */ +#endif /* _WIN32 */ } gchar * -- cgit v1.2.3