diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-12-31 18:45:00 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-01-01 05:19:49 +0000 |
commit | 8909dff72139d2f0514a7bb83c6bf5c2959c4101 (patch) | |
tree | efcc45cdde85039645dc49ffe715fcaa1f9e6b1f | |
parent | f30b1e3b3bc4cec85296c280cdae88d3d17fae04 (diff) |
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 <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r-- | epan/to_str.c | 54 |
1 files changed, 29 insertions, 25 deletions
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 * |