On 2025-09-23 10:05, Dag-Erling Smørgrav wrote:
I don't see much point in upstreaming FreeBSD's changes en masse.
Yes, and I wasn't planning to do that. Just one feature at a time.
The one change I'd like to see upstreamed (because it would reduce future
merge conflicts) is the offtime_r patch which I submitted and you
rejected two years ago.
In hindsight I was perhaps too strict and after all, NetBSD has
offtime_r too. So I installed the attached proposed patch to tzcode. (By
the way, offtime_r is not documented in FreeBSD, so is it present only
as a compatibility hack there?)
Getting back to the failure to conform to ISO C and POSIX with respect
to the pointers returned by gmtime and localtime - is that a bug that
FreeBSD would be willing to fix? If so, that'd simplify things on
tzcode's end, if we want to keep roughly in sync.
The DETECT_TZ_CHANGES patch may be of interest to others, but it should
be attributed to NetApp, Inc. rather than to FreeBSD.
What form should the attribution take? I don't see attribution in the
FreeBSD time source code. I assume Guy Harris wrote that so I'll cc him.From 3adf412336f8299dee3a81721564aadbcef60ebf Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Tue, 23 Sep 2025 11:34:19 -0700
Subject: [PROPOSED] =?UTF-8?q?Add=20offtime=5Fr=20=C3=A0=20la=20FreeBSD=20?=
=?UTF-8?q?and=20NetBSD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
It is not documented in FreeBSD, but is present.
Patch from Dag-Erling Smørgrav in:
https://lists.iana.org/hyperkitty/list/[email protected]/thread/UN3J6FHSYOHU6XFCLNVVNY6PQCWBYVKT/
* Makefile, NEWS: Mention this.
* localtime.c [!USE_TIMEX_T && STD_INSPIRED]:
(offtime_r): New function.
(offtime): Use it.
* private.h: Declare or define offtime_r.
---
Makefile | 4 +++-
NEWS | 4 ++++
localtime.c | 9 +++++++--
private.h | 5 +++++
4 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index cf1b7606..6aac7b2d 100644
--- a/Makefile
+++ b/Makefile
@@ -412,7 +412,9 @@ GCC_DEBUG_FLAGS = -DGCC_LINT -g3 -O3 \
# functions to be added to the time conversion library.
# "offtime" is like "gmtime" except that it accepts a second (long) argument
# that gives an offset to add to the time_t when converting it.
-# I.e., "offtime" is like calling "localtime_rz" with a fixed-offset zone.
+# "offtime_r" is to "offtime" what "gmtime_r" is to "gmtime".
+# I.e., "offtime" and "offtime_r" are like calling "localtime_rz"
+# with a fixed-offset zone.
# "timelocal" is nearly equivalent to "mktime".
# "timeoff" is like "timegm" except that it accepts a second (long) argument
# that gives an offset to use when converting to a time_t.
diff --git a/NEWS b/NEWS
index 0ad9b891..2421950e 100644
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,10 @@ Unreleased, experimental changes
and is abbreviated "UTC" not "-00". This reverts to 2024b behavior.
(Problem and patch reported by Dag-Erling Smørgrav.)
+ New function offtime_r, short for fixed-offset localtime_rz.
+ It is defined if STD_INSPIRED is defined.
+ (Patch from Dag-Erling Smørgrav.)
+
Changes to commentary
The leapseconds file contains commentary about the IERS and NIST
diff --git a/localtime.c b/localtime.c
index 1226e6e0..b32d475b 100644
--- a/localtime.c
+++ b/localtime.c
@@ -1770,14 +1770,19 @@ gmtime(const time_t *timep)
Callers can instead use localtime_rz with a fixed-offset zone. */
struct tm *
-offtime(const time_t *timep, long offset)
+offtime_r(time_t const *restrict timep, long offset, struct tm *restrict tmp)
{
gmtcheck();
+ return gmtsub(gmtptr, timep, offset, tmp);
+}
+struct tm *
+offtime(time_t const *timep, long offset)
+{
# if !SUPPORT_C89
static struct tm tm;
# endif
- return gmtsub(gmtptr, timep, offset, &tm);
+ return offtime_r(timep, offset, &tm);
}
# endif
diff --git a/private.h b/private.h
index 0a546e02..18fdf797 100644
--- a/private.h
+++ b/private.h
@@ -684,6 +684,8 @@ typedef time_tz tz_time_t;
# define mktime_z tz_mktime_z
# undef offtime
# define offtime tz_offtime
+# undef offtime_r
+# define offtime_r tz_offtime_r
# undef posix2time
# define posix2time tz_posix2time
# undef posix2time_z
@@ -820,6 +822,9 @@ extern long altzone;
# if TZ_TIME_T || !defined offtime
struct tm *offtime(time_t const *, long);
# endif
+# if TZ_TIME_T || !defined offtime_r
+struct tm *offtime_r(time_t const *restrict, long, struct tm *restrict);
+# endif
# if TZ_TIME_T || !defined timelocal
time_t timelocal(struct tm *);
# endif
--
2.48.1