]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
time_rz: tzfree now preserves errno
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 4 Nov 2025 16:10:49 +0000 (08:10 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 4 Nov 2025 16:11:41 +0000 (08:11 -0800)
This is consistent with bleeding-edge TZDB and with POSIX 'free'.
* lib/time.in.h (tzfree) [!HAVE_TZALLOC]: Replace tzfree.
I suspect Android and NetBSD (the major implementations) don’t
always preserve errno, and it’s easier to replace tzfree everywhere.
* lib/time_rz.c: Always include errno.h.
(tzfree) [HAVE_TZALLOC]: New replacement function.
(set_tz): Do not bother to save and restore errno,
now that tzfree preserves errno.
* modules/time_rz (Depends-on): Add free-posix.
(configure.ac, Makefile.am): Always compile time_rz.c.

ChangeLog
lib/time.in.h
lib/time_rz.c
m4/time_rz.m4
modules/time_rz

index 76903f733f6391a2855253e835cf477d8c1446a9..940ebffb52abf3cb008c160db01dff86c6068420 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2025-11-04  Paul Eggert  <eggert@cs.ucla.edu>
+
+       time_rz: tzfree now preserves errno
+       This is consistent with bleeding-edge TZDB and with POSIX 'free'.
+       * lib/time.in.h (tzfree) [!HAVE_TZALLOC]: Replace tzfree.
+       I suspect Android and NetBSD (the major implementations) don’t
+       always preserve errno, and it’s easier to replace tzfree everywhere.
+       * lib/time_rz.c: Always include errno.h.
+       (tzfree) [HAVE_TZALLOC]: New replacement function.
+       (set_tz): Do not bother to save and restore errno,
+       now that tzfree preserves errno.
+       * modules/time_rz (Depends-on): Add free-posix.
+       (configure.ac, Makefile.am): Always compile time_rz.c.
+
 2025-11-02  Paul Eggert  <eggert@cs.ucla.edu>
 
        fchmodat: don’t depend on openat
index 3ff16e3b3e4b24219278a1391f84de06111729de..d28702d2f61d78ebe03deede5ad88d8498c12e6d 100644 (file)
@@ -523,11 +523,18 @@ _GL_CXXALIAS_SYS (tzalloc, timezone_t, (char const *__name));
 #  endif
 
 /* tzfree (tz)
-   Frees a time zone object.
+   Free a time zone object, preserving errno.
    The argument must have been returned by tzalloc().  */
 #  if !@HAVE_TZALLOC@
 _GL_FUNCDECL_SYS (tzfree, void, (timezone_t __tz), );
 _GL_CXXALIAS_SYS (tzfree, void, (timezone_t __tz));
+#  else
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef tzfree
+#    define tzfree rpl_tzfree
+#   endif
+_GL_FUNCDECL_RPL (tzfree, void, (timezone_t __tz), );
+_GL_CXXALIAS_RPL (tzfree, void, (timezone_t __tz));
 #  endif
 
 /* localtime_rz (tz, &t, &result)
index 3a4336636fdc26e07568fbaf146b6b7990925271..8a8eb44c357edd54de8842a24d626dc89be99374 100644 (file)
 /* Specification.  */
 #include <time.h>
 
-#if NEED_TIMEZONE_NULL_SUPPORT          /* Android API level >= 35 */
+#include <errno.h>
+
+#if HAVE_TZALLOC
+# if NEED_TIMEZONE_NULL_SUPPORT          /* Android API level >= 35 */
 
 struct tm *
 localtime_rz (timezone_t tz, time_t const *t, struct tm *tm)
@@ -48,10 +51,19 @@ mktime_z (timezone_t tz, struct tm *tm)
   else
     return mktime_z (tz, tm);
 }
+# endif
+
+void
+tzfree (timezone_t tz)
+# undef tzfree
+{
+  int err = errno;
+  tzfree (tz);
+  errno = err;
+}
 
 #else
 
-# include <errno.h>
 # include <stddef.h>
 # include <stdlib.h>
 # include <string.h>
@@ -212,9 +224,7 @@ set_tz (timezone_t tz)
         return old_tz;
       if (! change_env (tz))
         {
-          int saved_errno = errno;
           tzfree (old_tz);
-          errno = saved_errno;
           return NULL;
         }
       return old_tz;
index b85e6d0cbb5d39643eb92e86f440fde636928079..885463a03b99e03e9ad4de93b76aa71c87be5f76 100644 (file)
@@ -1,5 +1,5 @@
 # time_rz.m4
-# serial 3
+# serial 4
 dnl Copyright (C) 2015-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -58,7 +58,8 @@ AC_DEFUN([gl_TIME_RZ],
   if test $ac_cv_func_tzalloc = yes; then
     HAVE_TZALLOC=1
   fi
-  dnl Assume that tzalloc, localtime_rz, mktime_z are all defined together.
+  dnl Assume that tzalloc, tzfree, localtime_rz, mktime_z
+  dnl are all defined together.
   case "$gl_cv_onwards_func_tzalloc" in
     yes)
       case "$host_os" in
index 1981b81920926deb41eec3d90e4bd12843e2f605..2479f04d1779a75a892cfa632b2e8fbcf554f041 100644 (file)
@@ -9,6 +9,7 @@ m4/time_rz.m4
 Depends-on:
 c99
 extensions
+free-posix
 time-h
 flexmember     [test $HAVE_TZALLOC = 0 || test $REPLACE_LOCALTIME_RZ = 1 || test $REPLACE_MKTIME_Z = 1]
 idx            [test $HAVE_TZALLOC = 0 || test $REPLACE_LOCALTIME_RZ = 1 || test $REPLACE_MKTIME_Z = 1]
@@ -22,14 +23,10 @@ unsetenv       [test $HAVE_TZALLOC = 0 || test $REPLACE_LOCALTIME_RZ = 1 || test
 
 configure.ac:
 gl_TIME_RZ
-gl_CONDITIONAL([GL_COND_OBJ_TIME_RZ],
-               [test $HAVE_TZALLOC = 0 || test $REPLACE_LOCALTIME_RZ = 1 || test $REPLACE_MKTIME_Z = 1])
 gl_TIME_MODULE_INDICATOR([time_rz])
 
 Makefile.am:
-if GL_COND_OBJ_TIME_RZ
 lib_SOURCES += time_rz.c
-endif
 
 Include:
 <time.h>