[29/59] Simplify setting tz_rules to UTC

Message ID 20250105055750.1668721-30-eggert@cs.ucla.edu (mailing list archive)
State New
Headers
Series time: sync mktime from Gnulib |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Paul Eggert Jan. 5, 2025, 5:57 a.m. UTC
  * time/tzset.c (__tzset_parse_tz): Reset to named UTC, not unnamed.
(tzset_internal): Rely on __tzset_parse_tz to reset state.
---
 time/tzset.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)
  

Patch

diff --git a/time/tzset.c b/time/tzset.c
index 2bbf8f055b..1873ad205b 100644
--- a/time/tzset.c
+++ b/time/tzset.c
@@ -352,11 +352,11 @@  parse_rule (const char **tzp, int whichrule)
 void
 __tzset_parse_tz (const char *tz)
 {
-  /* Clear out old state and reset to unnamed UTC.  */
+  /* Clear out old state and reset to UTC.  */
   memset (tz_rules, '\0', sizeof tz_rules);
   if (NO_DST != 0)
     tz_rules[0].type = tz_rules[1].type = NO_DST;
-  tz_rules[0].name = tz_rules[1].name = "";
+  tz_rules[0].name = tz_rules[1].name = "UTC";
 
   /* Get the standard time zone abbreviations.  */
   if (parse_tzname (&tz, 0) && parse_offset (&tz, 0))
@@ -410,9 +410,6 @@  tzset_internal (int always)
     /* No change, simply return.  */
     return;
 
-  tz_rules[0].name = NULL;
-  tz_rules[1].name = NULL;
-
   /* Save the value of `tz'.  */
   free (old_tz);
   old_tz = __strdup (tz);
@@ -422,18 +419,10 @@  tzset_internal (int always)
   if (__use_tzfile)
     return;
 
-  /* No data file found.  Default to UTC if nothing specified or if
+  /* No data file found.  Default to UTC without leap seconds if
      TZDEFAULT is broken.  */
-
-  if (*tz == '\0' || strcmp (tz, TZDEFAULT) == 0)
-    {
-      memset (tz_rules, '\0', sizeof tz_rules);
-      tz_rules[0].name = tz_rules[1].name = "UTC";
-      if (NO_DST != 0)
-	tz_rules[0].type = tz_rules[1].type = NO_DST;
-      update_vars ();
-      return;
-    }
+  if (strcmp (tz, TZDEFAULT) == 0)
+    tz = "";
 
   __tzset_parse_tz (tz);
 }