[tz] [PROPOSED PATCH] Declare timezone, daylight, altzone in private.h

Kees Dekker Kees.Dekker at infor.com
Fri Sep 18 06:00:53 UTC 2015

Hi Paul,

I unfortunately have no chance to test this. Excuse me. Probably later.


-----Original Message-----
From: Paul Eggert [mailto:eggert at cs.ucla.edu] 
Sent: Tuesday, September 15, 2015 08:38
To: tz at iana.org; Kees Dekker
Cc: Paul Eggert
Subject: [PROPOSED PATCH] Declare timezone, daylight, altzone in private.h

* NEWS: Document this.
* private.h (timezone, daylight) [USG_COMPAT]:
(altzone) [ALTZONE]:
Declare as extern if not defined as a macro.
This may avoid problems in environments where these variables
are not declared by the system <time.h>.
>From a suggestion by Kees Dekker in:
 NEWS      |  5 ++++-
 private.h | 13 +++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 37f461f..2bbb967 100644
--- a/NEWS
+++ b/NEWS
@@ -13,10 +13,13 @@ Unreleased, experimental changes
     (Thanks to Bradley White for reporting the bug.)
     The localtime module allows the variables 'timezone', 'daylight',
-    and 'altzone' to be in common storage shared with other modules.
+    and 'altzone' to be in common storage shared with other modules,
+    and declares them in case the system <time.h> does not.
+    (Problems reported by Kees Dekker.)
     On platforms with tm_zone, strftime.c now assumes it is not NULL.
     This simplifies the code and is consistent with zdump.c.
+    (Problem reported by Christos Zoulas.)
   Changes affecting documentation
diff --git a/private.h b/private.h
index 184da8f..1c176e6 100644
--- a/private.h
+++ b/private.h
@@ -383,12 +383,25 @@ void tzset(void);
 ** Some time.h implementations don't declare asctime_r.
 ** Others might define it as a macro.
 ** Fix the former without affecting the latter.
+** Similarly for timezone, daylight, and altzone.
 #ifndef asctime_r
 extern char *	asctime_r(struct tm const *restrict, char *restrict);
+#ifdef USG_COMPAT
+# ifndef timezone
+extern long timezone;
+# endif
+# ifndef daylight
+extern int daylight;
+# endif
+#if defined ALTZONE && !defined altzone
+extern long altzone;
 ** The STD_INSPIRED functions are similar, but most also need
 ** declarations if time_tz is defined.

More information about the tz mailing list