[tz] [PROPOSED PATCH 8/9] Add NetBSD-inspired functions for timezone_t objects.

Paul Eggert eggert at cs.ucla.edu
Mon Aug 25 08:03:53 UTC 2014


Alan Barrett wrote:
> a null
> pointer may be passed instead of a timezone_t, and this is a shorthand
> for UTC.

Thanks, I hadn't noticed this.  localtime_rz already does this but 
mktime_z and tzalloc don't.  Proposed further patch attached.
-------------- next part --------------
From 6d569fab74f1e9819c328adfa064bb72578b2df6 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert at cs.ucla.edu>
Date: Mon, 25 Aug 2014 01:02:07 -0700
Subject: [PROPOSED PATCH] Improve compatibility with NetBSD with respect to
 null pointers.

Problem reported by Alan Barrett in:
http://mm.icann.org/pipermail/tz/2014-August/021518.html
* localtime.c (zoneinit): Use UTC if !name.
That way, tzalloc(NULL) returns UTC, as in NetBSD.
(mktime_z): Use UTC if !sp.
* NEWS: Document this.
---
 NEWS        |  3 ++-
 localtime.c | 18 +++++++++++++-----
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/NEWS b/NEWS
index 18b6aec..fb2f31b 100644
--- a/NEWS
+++ b/NEWS
@@ -61,7 +61,8 @@ Unreleased, experimental changes
     zones simultaneously, e.g., an application where each thread may be
     in a different time zone.  The new functions are tzalloc, tzfree,
     localtime_rz, mktime_z, and (if STD_INSPIRED is also defined)
-    posix2time_z and time2posix_z.
+    posix2time_z and time2posix_z.  (Thanks to Alan Barrett for
+    helping to debug this.)
 
     The tz code now attempts to infer TM_GMTOFF and TM_ZONE if not
     already defined, to make it easier to configure on common platforms.
diff --git a/localtime.c b/localtime.c
index c68b575..d5fd508 100644
--- a/localtime.c
+++ b/localtime.c
@@ -1205,7 +1205,12 @@ static struct state *
 zoneinit(struct state *sp, char const *name)
 {
   if (sp) {
-    if (*name == '\0') {
+    if (! name
+	|| (name[0]
+	    && ! (tzload(name, sp, true)
+		  || (name[0] != ':' && tzparse(name, sp, false)))))
+      gmtload(sp);
+    else if (! name[0]) {
       /*
       ** User wants it fast rather than right.
       */
@@ -1216,9 +1221,7 @@ zoneinit(struct state *sp, char const *name)
       sp->ttis[0].tt_gmtoff = 0;
       sp->ttis[0].tt_abbrind = 0;
       strcpy(sp->chars, gmt);
-    } else if (! tzload(name, sp, true))
-      if (name[0] == ':' || ! tzparse(name, sp, false))
-	gmtload(sp);
+    }
   }
   return sp;
 }
@@ -2029,7 +2032,12 @@ time1(struct tm *const tmp,
 NETBSD_INSPIRED_EXTERN time_t
 mktime_z(struct state *sp, struct tm *tmp)
 {
-  return time1(tmp, localsub, sp, 0);
+  if (sp)
+    return time1(tmp, localsub, sp, 0);
+  else {
+    gmtcheck();
+    return time1(tmp, gmtsub, gmtptr, 0);
+  }
 }
 
 time_t
-- 
1.9.1


More information about the tz mailing list