changeset 18067:0295f80643fc

strftime: fix newly-introduced bug on Solaris * lib/strftime.c (strftime_case_): Set the local variable 'zone' consistently at the start, rather than doing some of the setup at the start and some in the %Z format spec. This is cleaner, and works better with time_rz on platforms like Solaris where struct tm lacks a tm_zone member, as when !HAVE_TM_GMTOFF %z's calls to mktime_z and localtime_rz can mess up the tzname cache.
author Paul Eggert <eggert@cs.ucla.edu>
date Sat, 25 Jul 2015 16:37:17 -0700
parents fc4efc29b92e
children 90195ad97c8b
files ChangeLog lib/strftime.c
diffstat 2 files changed, 13 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2015-07-25  Paul Eggert  <eggert@cs.ucla.edu>
 
+	strftime: fix newly-introduced bug on Solaris
+	* lib/strftime.c (strftime_case_): Set the local variable 'zone'
+	consistently at the start, rather than doing some of the setup at
+	the start and some in the %Z format spec.  This is cleaner, and
+	works better with time_rz on platforms like Solaris where struct
+	tm lacks a tm_zone member, as when !HAVE_TM_GMTOFF %z's calls to
+	mktime_z and localtime_rz can mess up the tzname cache.
+
 	test-strftime: test for Solaris bug
 	* modules/strftime-tests (Depends-on): Add strerror.
 	* tests/test-strftime.c: Include <errno.h>.
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -481,7 +481,12 @@
       tzset ();
 # endif
     }
+  /* The tzset() call might have changed the value.  */
+  if (!(zone && *zone) && tp->tm_isdst >= 0)
+    zone = tzname[tp->tm_isdst != 0];
 #endif
+  if (! zone)
+    zone = "";
 
   if (hour12 > 12)
     hour12 -= 12;
@@ -1304,14 +1309,6 @@
               to_lowcase = true;
             }
 
-#if HAVE_TZNAME
-          /* The tzset() call might have changed the value.  */
-          if (!(zone && *zone) && tp->tm_isdst >= 0)
-            zone = tzname[tp->tm_isdst != 0];
-#endif
-          if (! zone)
-            zone = "";
-
 #ifdef COMPILE_WIDE
           {
             /* The zone string is always given in multibyte form.  We have