From: Bruno Haible 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=67f5847651214d9b4ad4ca4a349c95e10763dece;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 eb8dde396b..308bec6bc7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-06-06 Bruno Haible + + 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 tzname: Add tests. diff --git a/lib/time-internal.h b/lib/time-internal.h index 51423c94ca..045e9e0ac7 100644 --- a/lib/time-internal.h +++ b/lib/time-internal.h @@ -1,6 +1,6 @@ /* Time internal interface - Copyright 2015-2023 Free Software Foundation, Inc. + Copyright 2015-2024 Free Software Foundation, Inc. This file is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -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 da0d57b8b1..b28d55c2fd 100644 --- a/lib/time_rz.c +++ b/lib/time_rz.c @@ -1,6 +1,6 @@ /* Time zone functions such as tzalloc and localtime_rz - Copyright 2015-2023 Free Software Foundation, Inc. + Copyright 2015-2024 Free Software Foundation, Inc. This file is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -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 d13bc06b7a..c7387ca9a2 100644 --- a/m4/time_rz.m4 +++ b/m4/time_rz.m4 @@ -1,6 +1,6 @@ dnl Time zone functions: tzalloc, localtime_rz, etc. -dnl Copyright (C) 2015-2023 Free Software Foundation, Inc. +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, dnl with or without modifications, as long as this notice is preserved. @@ -11,7 +11,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]