From 24b45243c5210b4196987fdd06e6c288c358a268 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 14 Feb 2018 15:57:06 -0800
Subject: [PROPOSED 1/2] Port to systems where localtime etc. are reserved

Problem reported by Manuela Friedrich for MS-Windows in:
https://mm.icann.org/pipermail/tz/2018-February/026228.html
* private.h (USE_LTZ): Move here from zdump.c
(RESERVE_STD_EXT_IDS): Default to 0.
(time_tz): Define to time_t if standard C identifiers are reserved
and are not being renamed already.
---
 Makefile  |  2 ++
 NEWS      |  4 +++-
 private.h | 20 ++++++++++++++++++++
 zdump.c   | 10 ----------
 4 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile
index 659a5b0..ad3b123 100644
--- a/Makefile
+++ b/Makefile
@@ -205,6 +205,8 @@ LDLIBS=
 #  -DHAVE_TZSET=0 if your system lacks a tzset function
 #  -DHAVE_UNISTD_H=0 if your compiler lacks a <unistd.h>
 #  -Dlocale_t=XXX if your system uses XXX instead of locale_t
+#  -DRESERVE_STD_EXT_IDS if your platform reserves standard identifiers
+#	with external linkage, e.g., applications cannot define 'localtime'.
 #  -Dssize_t=long on hosts like MS-Windows that lack ssize_t
 #  -DTHREAD_SAFE to make localtime.c thread-safe, as POSIX requires;
 #	not needed by the main-program tz code, which is single-threaded.
diff --git a/NEWS b/NEWS
index 8e0b861..09ee326 100644
--- a/NEWS
+++ b/NEWS
@@ -60,7 +60,9 @@ Unreleased, experimental changes
     to use this feature.  (Thanks to Steve Allen for pointing out
     the limitations of historical data in this area.)
 
-    The code is a bit more portable to MS-Windows.  (Thanks to Manuela
+    The code is a bit more portable to MS-Windows.  Installers can
+    compile with -DRESERVE_STD_EXT_IDS on MS-Windows platforms that
+    reserve identifiers like 'localtime'.  (Thanks to Manuela
     Friedrich).
 
   Changes to documentation and commentary
diff --git a/private.h b/private.h
index ffb8121..705544e 100644
--- a/private.h
+++ b/private.h
@@ -15,6 +15,16 @@
 ** Thank you!
 */
 
+/*
+** zdump has been made independent of the rest of the time
+** conversion package to increase confidence in the verification it provides.
+** You can use zdump to help in verifying other implementations.
+** To do this, compile with -DUSE_LTZ=0 and link without the tz library.
+*/
+#ifndef USE_LTZ
+# define USE_LTZ 1
+#endif
+
 /* This string was in the Factory zone through version 2016f.  */
 #define GRANDPARENTED	"Local time zone must be set--see zic manual page"
 
@@ -364,6 +374,16 @@ typedef unsigned long uintmax_t;
 #ifndef EPOCH_OFFSET
 # define EPOCH_OFFSET 0
 #endif
+#ifndef RESERVE_STD_EXT_IDS
+# define RESERVE_STD_EXT_IDS 0
+#endif
+
+/* If standard C identifiers with external linkage (e.g., localtime)
+   are reserved and are not already being renamed anyway, rename them
+   as if compiling with '-Dtime_tz=time_t'.  */
+#if !defined time_tz && RESERVE_STD_EXT_IDS && USE_LTZ
+# define time_tz time_t
+#endif
 
 /*
 ** Compile with -Dtime_tz=T to build the tz package with a private
diff --git a/zdump.c b/zdump.c
index 60a027e..1081648 100644
--- a/zdump.c
+++ b/zdump.c
@@ -5,19 +5,9 @@
 
 #include "version.h"
 
-/*
-** This code has been made independent of the rest of the time
-** conversion package to increase confidence in the verification it provides.
-** You can use this code to help in verifying other implementations.
-** To do this, compile with -DUSE_LTZ=0 and link without the tz library.
-*/
-
 #ifndef NETBSD_INSPIRED
 # define NETBSD_INSPIRED 1
 #endif
-#ifndef USE_LTZ
-# define USE_LTZ 1
-#endif
 
 #include "private.h"
 #include <stdio.h>
-- 
2.7.4

