]> Savannah Git Hosting - gnulib.git/commitdiff
tzset: Work around TZ problem on native Windows.
authorBruno Haible <bruno@clisp.org>
Mon, 1 May 2017 15:27:53 +0000 (17:27 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 1 May 2017 16:37:41 +0000 (18:37 +0200)
* m4/tzset.m4 (gl_FUNC_TZSET): Require AC_CANONICAL_HOST. On native
Windows, set REPLACE_TZSET to 1.
* lib/tzset.c (tzset): On native Windows, fix TZ if necessary, and
invoke '_tzset' instead of 'tzset'.
* doc/posix-functions/tzset.texi: Mention the native Windows workaround.

* modules/time_rz (Depends-on): Add tzset.
* lib/time_rz.c (tzset): Remove fallback definition.
* m4/time_rz.m4 (gl_TIME_RZ): Don't test for tzset.

ChangeLog
doc/posix-functions/tzset.texi
lib/time_rz.c
lib/tzset.c
m4/time_rz.m4
m4/tzset.m4
modules/time_rz

index bafd2eb2e683f3f58007a5c54a20a1dbf9ea23c7..64231468b30937beed3a5729894d65b001ce08b5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2017-05-01  Bruno Haible  <bruno@clisp.org>
+
+       tzset: Work around TZ problem on native Windows.
+       * m4/tzset.m4 (gl_FUNC_TZSET): Require AC_CANONICAL_HOST. On native
+       Windows, set REPLACE_TZSET to 1.
+       * lib/tzset.c (tzset): On native Windows, fix TZ if necessary, and
+       invoke '_tzset' instead of 'tzset'.
+       * doc/posix-functions/tzset.texi: Mention the native Windows workaround.
+
+       * modules/time_rz (Depends-on): Add tzset.
+       * lib/time_rz.c (tzset): Remove fallback definition.
+       * m4/time_rz.m4 (gl_TIME_RZ): Don't test for tzset.
+
 2017-05-01  Bruno Haible  <bruno@clisp.org>
 
        mktime: Fix dependencies.
index 30b147cc3cd44e94e935b73cb3ea178492e8cb8e..a457409352a1ad4e3dc4a5f9d7a9a6129fec5108 100644 (file)
@@ -9,6 +9,9 @@ Gnulib module: tzset
 Portability problems fixed by Gnulib:
 @itemize
 @item
+On native Windows platforms (mingw, MSVC), this function works incorrectly
+when the environment variable @code{TZ} has been set by Cygwin.
+@item
 This function clobbers the buffer used by the localtime function on some
 platforms:
 Solaris 2.6.
@@ -16,7 +19,4 @@ Solaris 2.6.
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-On native Windows platforms (mingw, MSVC), this function works incorrectly
-when the environment variable @code{TZ} has been set by Cygwin.
 @end itemize
index 82f3f3f19dc5beae04ac1c567daaebaa666bc6c8..95c7293fef5132e4aaca757d78338b7a0761045d 100644 (file)
 # define SIZE_MAX ((size_t) -1)
 #endif
 
-#if !HAVE_TZSET
-static void tzset (void) { }
-#endif
-
 /* The approximate size to use for small allocation requests.  This is
    the largest "small" request for the GNU C library malloc.  */
 enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
index 1cb9822146bd3a492d98e8b5410005202b8c7ae0..ce854b9f11e536d6a96a35fe0380cbcf8b783c65 100644 (file)
@@ -40,7 +40,23 @@ tzset (void)
   struct tm save = *localtime_buffer_addr;
 #endif
 
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  /* If the environment variable TZ has been set by Cygwin, neutralize it.
+     The Microsoft CRT interprets TZ differently than Cygwin and produces
+     incorrect results if TZ has the syntax used by Cygwin.  */
+  const char *tz = getenv ("TZ");
+  if (tz != NULL && strchr (tz, '/') != NULL)
+    _putenv ("TZ=");
+
+  /* On native Windows, tzset() is deprecated.  Use _tzset() instead.  See
+     https://msdn.microsoft.com/en-us/library/ms235451.aspx
+     https://msdn.microsoft.com/en-us/library/90s5c885.aspx  */
+  _tzset ();
+#elif HAVE_TZSET
   tzset ();
+#else
+  /* Do nothing.  Avoid infinite recursion.  */
+#endif
 
 #if TZSET_CLOBBERS_LOCALTIME
   *localtime_buffer_addr = save;
index 79060e00fccc739d7c32f5d635490c8b228ae0a3..079e933b4e65522ed031a9ba02865e2209556b27 100644 (file)
@@ -12,7 +12,6 @@ AC_DEFUN([gl_TIME_RZ],
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
   AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
   AC_REQUIRE([AC_STRUCT_TIMEZONE])
-  AC_CHECK_FUNCS_ONCE([tzset])
 
   AC_CHECK_TYPES([timezone_t], [], [], [[#include <time.h>]])
   if test "$ac_cv_type_timezone_t" = yes; then
index 20939e9b6a09a666d2c4adc5994ebf953ae517f2..08362fea739acd0f94920feca3020c3cedd3f9e0 100644 (file)
@@ -17,11 +17,13 @@ AC_DEFUN([gl_FUNC_TZSET],
 [
   AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
   AC_REQUIRE([gl_LOCALTIME_BUFFER_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
   AC_CHECK_FUNCS_ONCE([tzset])
   if test $ac_cv_func_tzset = no; then
     HAVE_TZSET=0
   fi
   gl_FUNC_TZSET_CLOBBER
+  REPLACE_TZSET=0
   case "$gl_cv_func_tzset_clobber" in
     *yes)
       REPLACE_TZSET=1
@@ -29,9 +31,9 @@ AC_DEFUN([gl_FUNC_TZSET],
         [Define if tzset clobbers localtime's static buffer.])
       gl_LOCALTIME_BUFFER_NEEDED
       ;;
-    *)
-      REPLACE_TZSET=0
-      ;;
+  esac
+  case "$host_os" in
+    mingw*) REPLACE_TZSET=1 ;;
   esac
 ])
 
index e934d557202b32eb958175d6d5308477b6cb1de4..1bc29f401f1e5c5a580215fc095c5a14c99df537 100644 (file)
@@ -24,6 +24,7 @@ setenv         [test "$HAVE_TIMEZONE_T" = 0]
 stdbool        [test "$HAVE_TIMEZONE_T" = 0]
 time_r         [test "$HAVE_TIMEZONE_T" = 0]
 timegm         [test "$HAVE_TIMEZONE_T" = 0]
+tzset          [test "$HAVE_TIMEZONE_T" = 0]
 unsetenv       [test "$HAVE_TIMEZONE_T" = 0]
 
 configure.ac: