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-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
# 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)
/* 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)
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>
return old_tz;
if (! change_env (tz))
{
- int saved_errno = errno;
tzfree (old_tz);
- errno = saved_errno;
return NULL;
}
return old_tz;
# 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,
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
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]
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>