[tz] [PROPOSED PATCH] Simplify configuration of TM_GMTOFF and TM_ZONE.

Paul Eggert eggert at cs.ucla.edu
Sat Aug 23 05:04:09 UTC 2014


One other thing that needs fixing, which is that zdump.c should have the 
same defaults that private.h does.  Revised patch (with David Byron's 
spelling fix) attached.  At some point we should be moving all this 
duplicated code into a new .h file, I suppose.
-------------- next part --------------
From 30d18e7f92d5bad79cbd86b05338874988c841d7 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert at cs.ucla.edu>
Date: Tue, 19 Aug 2014 18:16:15 -0700
Subject: [PROPOSED PATCH] Simplify configuration of TM_GMTOFF and TM_ZONE.

* private.h, zdump.c (_GNU_SOURCE): New macro.
(TM_GMTOFF) [!NO_TM_GMTOFF]:
(TM_ZONE) [!NO_TM_ZONE]: Guess definition if not already defined.
* Makefile, NEWS: Document the above.
---
 Makefile  | 23 +++++------------------
 NEWS      |  4 ++++
 private.h | 16 ++++++++++++++++
 zdump.c   | 16 ++++++++++++++++
 4 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/Makefile b/Makefile
index 4703cba..d36bc43 100644
--- a/Makefile
+++ b/Makefile
@@ -161,25 +161,12 @@ GCC_DEBUG_FLAGS = -Dlint -g3 -O3 -fno-common -fstrict-aliasing \
 # (or if you decide to add such a field in your system's "time.h" file),
 # add the name to a define such as
 #	-DTM_GMTOFF=tm_gmtoff
-# or
-#	-DTM_GMTOFF=_tm_gmtoff
-# to the end of the "CFLAGS=" line.
-# Neither tm_gmtoff nor _tm_gmtoff is described in X3J11's work;
-# in its work, use of "tm_gmtoff" is described as non-conforming.
-# Both Linux and BSD have done the equivalent of defining TM_GMTOFF in
-# their recent releases.
-#
-# If your system has a "zone abbreviation" field in its "struct tm"s
-# (or if you decide to add such a field in your system's "time.h" file),
-# add the name to a define such as
+# to the end of the "CFLAGS=" line.  If not defined, the code attempts to
+# guess TM_GMTOFF from other macros; define NO_TM_GMTOFF to suppress this.
+# Similarly, if your system has a "zone abbreviation" field, define
 #	-DTM_ZONE=tm_zone
-# or
-#	-DTM_ZONE=_tm_zone
-# to the end of the "CFLAGS=" line.
-# Neither tm_zone nor _tm_zone is described in X3J11's work;
-# in its work, use of "tm_zone" is described as non-conforming.
-# Both UCB and Sun have done the equivalent of defining TM_ZONE in
-# their recent releases.
+# and define NO_TM_ZONE to suppress any guessing.  These two fields are not
+# required by POSIX, but are widely available on GNU/Linux and BSD systems.
 #
 # If you want functions that were inspired by early versions of X3J11's work,
 # add
diff --git a/NEWS b/NEWS
index 335a7cf..7bc8b05 100644
--- a/NEWS
+++ b/NEWS
@@ -51,6 +51,10 @@ Unreleased, experimental changes
     Although not needed for tz's own applications, which are single-threaded,
     this supports POSIX better if the tz library is used in multithreaded apps.
 
+    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.
+    Define NO_TM_GMTOFF and NO_TM_ZONE to suppress this.
+
     tzselect -c now uses a hybrid distance measure that works better
     in Africa.  (Thanks to Alan Barrett for noting the problem.)
 
diff --git a/private.h b/private.h
index 9482790..2389e37 100644
--- a/private.h
+++ b/private.h
@@ -71,6 +71,9 @@
 #define ctime_r _incompatible_ctime_r
 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
 
+/* Enable tm_gmtoff and tm_zone on GNUish systems.  */
+#define _GNU_SOURCE 1
+
 /*
 ** Nested includes
 */
@@ -337,6 +340,19 @@ time_t posix2time(time_t);
 # endif
 #endif
 
+/* Infer TM_ZONE on systems where this information is known, but suppress
+   guessing if NO_TM_ZONE is defined.  Similarly for TM_GMTOFF.  */
+#if (defined __GLIBC__ \
+     || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
+     || (defined __APPLE__ && defined __MACH__))
+# if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
+#  define TM_GMTOFF tm_gmtoff
+# endif
+# if !defined TM_ZONE && !defined NO_TM_ZONE
+#  define TM_ZONE tm_zone
+# endif
+#endif
+
 /*
 ** Private function declarations.
 */
diff --git a/zdump.c b/zdump.c
index 226b7ac..79286bf 100644
--- a/zdump.c
+++ b/zdump.c
@@ -18,6 +18,9 @@
 # include "private.h"
 #endif
 
+/* Enable tm_gmtoff and tm_zone on GNUish systems.  */
+#define _GNU_SOURCE 1
+
 #include "stdio.h"	/* for stdout, stderr, perror */
 #include "string.h"	/* for strcpy */
 #include "sys/types.h"	/* for time_t */
@@ -73,6 +76,19 @@ typedef long intmax_t;
 # endif
 #endif
 
+/* Infer TM_ZONE on systems where this information is known, but suppress
+   guessing if NO_TM_ZONE is defined.  Similarly for TM_GMTOFF.  */
+#if (defined __GLIBC__ \
+     || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
+     || (defined __APPLE__ && defined __MACH__))
+# if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
+#  define TM_GMTOFF tm_gmtoff
+# endif
+# if !defined TM_ZONE && !defined NO_TM_ZONE
+#  define TM_ZONE tm_zone
+# endif
+#endif
+
 
 #ifndef ZDUMP_LO_YEAR
 #define ZDUMP_LO_YEAR	(-500)
-- 
1.9.1


More information about the tz mailing list