[27/59] TZ="" always means UTC sans leap seconds

Message ID 20250105055750.1668721-28-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
  TZ="" now always means UTC without leap seconds.
This agrees better with doc and with tzcode,
where TZ="" is intended to be a performance hack.
* manual/time.texi (TZ Variable): Clarify that TZ=":" is equivalent
to TZ="", and that both mean UTC without leap seconds.
* time/tzfile.c (__tzfile_read): Check for TZ="" here,
so that __use_tzfile is set properly.
* time/tzset.c (tzset_internal): Simplify by relying on
__tzfile_read to check for TZ="".
---
 NEWS               |  7 +++++++
 manual/time.texi   | 10 +++++-----
 time/tzfile.c      |  3 +++
 time/tzset.c       | 13 +++----------
 timezone/test-tz.c |  1 +
 5 files changed, 19 insertions(+), 15 deletions(-)
  

Patch

diff --git a/NEWS b/NEWS
index a62fb8136d..a737a0124b 100644
--- a/NEWS
+++ b/NEWS
@@ -90,6 +90,13 @@  Deprecated and removed features, and other changes affecting compatibility:
   /usr/share/zoneinfo/posixrules but this did not work and in practice
   posixrules invariably specified the US rule anyway.
 
+* TZ="" now always agrees with TZ=":" and means UTC without leap seconds.
+  Previously TZ="" meant UTC with leap seconds on the rare systems
+  configured to use leap seconds by default.  However, this behavior
+  disagreed with both the glibc manual (which said that TZ="" and TZ=":"
+  have the same behavior) and with tzcode upstream, and it did not work
+  in some cases.
+
 Changes to build and runtime requirements:
 
 * On recent Linux kernels with vDSO getrandom support, getrandom does not
diff --git a/manual/time.texi b/manual/time.texi
index cff94cb48b..d5619534a5 100644
--- a/manual/time.texi
+++ b/manual/time.texi
@@ -2642,6 +2642,10 @@  EST+5EDT,M3.2.0/2,M11.1.0/2
 <-02>+2<-01>,M3.5.0/-1,M10.5.0/0
 @end smallexample
 
+@item
+As an extension to POSIX, when the value of @env{TZ} is the empty string,
+@theglibc{} uses UTC without leap seconds.
+
 @item
 The @dfn{colon format} begins with @samp{:}.  Here is an example.
 
@@ -2652,11 +2656,7 @@  The @dfn{colon format} begins with @samp{:}.  Here is an example.
 @noindent
 Each operating system can interpret this format differently;
 in @theglibc{}, the @samp{:} is ignored and @var{characters}
-are treated as if they specified the geographical or proleptic format.
-
-@item
-As an extension to POSIX, when the value of @env{TZ} is the empty string,
-@theglibc{} uses UTC.
+are treated as if they specified one of the other formats.
 @end itemize
 
 @pindex /etc/localtime
diff --git a/time/tzfile.c b/time/tzfile.c
index 08cf0686df..4ca1f3c0c8 100644
--- a/time/tzfile.c
+++ b/time/tzfile.c
@@ -172,6 +172,9 @@  __tzfile_read (const char *file)
 
   if (*file != '/')
     {
+      if (*file == '\0')
+	goto ret_free_transitions;
+
       const char *tzdir;
 
       tzdir = getenv ("TZDIR");
diff --git a/time/tzset.c b/time/tzset.c
index b014bca8d3..c2575edad9 100644
--- a/time/tzset.c
+++ b/time/tzset.c
@@ -399,10 +399,6 @@  tzset_internal (int always)
     /* No user specification; use the site-wide default.  */
     tz = TZDEFAULT;
 
-  if (*tz == '\0')
-    /* User specified the empty string; use UTC explicitly.  */
-    tz = "Universal";
-
   /* A leading colon means "implementation defined syntax".
      We ignore the colon and always use the same algorithm:
      try a data file, and if none exists parse the 1003.1 syntax.  */
@@ -422,12 +418,9 @@  tzset_internal (int always)
   old_tz = __strdup (tz);
 
   /* Try to read a data file.  */
-  if (*tz != '\0')
-    {
-      __tzfile_read (tz);
-      if (__use_tzfile)
-	return;
-    }
+  __tzfile_read (tz);
+  if (__use_tzfile)
+    return;
 
   /* No data file found.  Default to UTC if nothing specified or if
      TZDEFAULT is broken.  */
diff --git a/timezone/test-tz.c b/timezone/test-tz.c
index 642b45a0ed..597096a5c0 100644
--- a/timezone/test-tz.c
+++ b/timezone/test-tz.c
@@ -8,6 +8,7 @@  struct {
   time_t	expected;
 } tests[] = {
   {"MST",	832935315},
+  {":",		832910115},
   {"",		832910115},
   {":UTC",	832910115},
   {"UTC",	832910115},