From: Bruno Haible <bruno@clisp.org>
Date: Thu, 6 Jun 2024 16:17:23 +0000 (+0200)
Subject: time_rz: Support time zone names on MSVC.
X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=14b9063716442d81770554ad33a635125d56194f;p=gnulib.git

time_rz: Support time zone names on MSVC.

* lib/time-internal.h: Use HAVE_TZNAME_ARRAY instead of HAVE_TZNAME.
* lib/time_rz.c (tzalloc, save_abbr, mktime_z): Likewise.
* modules/time_rz (Depends-on): Add tzname.
* m4/time_rz.m4 (gl_TIME_RZ): Don't require AC_STRUCT_TIMEZONE.
---

diff --git a/ChangeLog b/ChangeLog
index 78af4a7090..16b1ec8496 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-06-06  Bruno Haible  <bruno@clisp.org>
+
+	time_rz: Support time zone names on MSVC.
+	* lib/time-internal.h: Use HAVE_TZNAME_ARRAY instead of HAVE_TZNAME.
+	* lib/time_rz.c (tzalloc, save_abbr, mktime_z): Likewise.
+	* modules/time_rz (Depends-on): Add tzname.
+	* m4/time_rz.m4 (gl_TIME_RZ): Don't require AC_STRUCT_TIMEZONE.
+
 2024-06-06  Bruno Haible  <bruno@clisp.org>
 
 	tzname: Add tests.
diff --git a/lib/time-internal.h b/lib/time-internal.h
index 816684a117..045e9e0ac7 100644
--- a/lib/time-internal.h
+++ b/lib/time-internal.h
@@ -24,7 +24,7 @@ struct tm_zone
      members are zero.  */
   struct tm_zone *next;
 
-#if HAVE_TZNAME && !HAVE_STRUCT_TM_TM_ZONE
+#if HAVE_TZNAME_ARRAY && !HAVE_STRUCT_TM_TM_ZONE
   /* Copies of recent strings taken from tzname[0] and tzname[1].
      The copies are in ABBRS, so that they survive tzset.  Null if unknown.  */
   char *tzname_copy[2];
diff --git a/lib/time_rz.c b/lib/time_rz.c
index 468d7539ce..b28d55c2fd 100644
--- a/lib/time_rz.c
+++ b/lib/time_rz.c
@@ -70,7 +70,7 @@ tzalloc (char const *name)
   if (tz)
     {
       tz->next = NULL;
-#if HAVE_TZNAME && !HAVE_STRUCT_TM_TM_ZONE
+#if HAVE_TZNAME_ARRAY && !HAVE_STRUCT_TM_TM_ZONE
       tz->tzname_copy[0] = tz->tzname_copy[1] = NULL;
 #endif
       tz->tz_is_set = !!name;
@@ -81,18 +81,19 @@ tzalloc (char const *name)
   return tz;
 }
 
-/* Save into TZ any nontrivial time zone abbreviation used by TM, and
-   update *TM (if HAVE_STRUCT_TM_TM_ZONE) or *TZ (if
-   !HAVE_STRUCT_TM_TM_ZONE && HAVE_TZNAME) if they use the abbreviation.
+/* Save into TZ any nontrivial time zone abbreviation used by TM, and update
+      *TM (if HAVE_STRUCT_TM_TM_ZONE)
+   or *TZ (if !HAVE_STRUCT_TM_TM_ZONE && HAVE_TZNAME_ARRAY)
+   if they use the abbreviation.
    Return true if successful, false (setting errno) otherwise.  */
 static bool
 save_abbr (timezone_t tz, struct tm *tm)
 {
-#if HAVE_STRUCT_TM_TM_ZONE || HAVE_TZNAME
+#if HAVE_STRUCT_TM_TM_ZONE || HAVE_TZNAME_ARRAY
   char const *zone = NULL;
   char *zone_copy = (char *) "";
 
-# if HAVE_TZNAME
+# if HAVE_TZNAME_ARRAY
   int tzname_index = -1;
 # endif
 
@@ -100,7 +101,7 @@ save_abbr (timezone_t tz, struct tm *tm)
   zone = tm->tm_zone;
 # endif
 
-# if HAVE_TZNAME
+# if HAVE_TZNAME_ARRAY
   if (! (zone && *zone) && 0 <= tm->tm_isdst)
     {
       tzname_index = tm->tm_isdst != 0;
@@ -302,7 +303,7 @@ mktime_z (timezone_t tz, struct tm *tm)
           tm_1.tm_isdst = tm->tm_isdst;
           time_t t = mktime (&tm_1);
           bool ok = 0 <= tm_1.tm_yday;
-#if HAVE_STRUCT_TM_TM_ZONE || HAVE_TZNAME
+#if HAVE_STRUCT_TM_TM_ZONE || HAVE_TZNAME_ARRAY
           ok = ok && save_abbr (tz, &tm_1);
 #endif
           if (revert_tz (old_tz) && ok)
diff --git a/m4/time_rz.m4 b/m4/time_rz.m4
index 8f45f2b1d3..9613597aca 100644
--- a/m4/time_rz.m4
+++ b/m4/time_rz.m4
@@ -1,5 +1,5 @@
 # time_rz.m4
-# serial 1
+# serial 2
 dnl Copyright (C) 2015-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -13,7 +13,6 @@ AC_DEFUN([gl_TIME_RZ],
 [
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
   AC_REQUIRE([gl_TIME_H_DEFAULTS])
-  AC_REQUIRE([AC_STRUCT_TIMEZONE])
 
   # On Mac OS X 10.6, localtime loops forever with some time_t values.
   # See Bug#27706, Bug#27736, and
diff --git a/modules/time_rz b/modules/time_rz
index f487e24c6b..da621684f5 100644
--- a/modules/time_rz
+++ b/modules/time_rz
@@ -10,6 +10,7 @@ Depends-on:
 c99
 extensions
 time-h
+tzname
 flexmember     [test $HAVE_TIMEZONE_T = 0]
 idx            [test $HAVE_TIMEZONE_T = 0]
 setenv         [test $HAVE_TIMEZONE_T = 0]