Thanks for reporting that. I installed the attached; the first is your
patch with very minor changes; the second documents the change.
I didn't know this this code was used in freebsd-src/contrib/tzcode. I
now see that there are some minor differences between the FreeBSD copy;
would it make sense to merge these into tzcode, perhaps with some
"#ifdef __FreeBSD__"s thrown in? I suspect that would save time overall
in the long run.From 75e74e90ecdfb463b1a882194716936e38992080 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= <[email protected]>
Date: Mon, 22 Sep 2025 12:10:09 -0700
Subject: [PROPOSED 1/2] Use -00 only for invalid time zones
* localtime.c (tzset_unlocked): If TZ is unset and TZDEFAULT does
not exist, fall back to "UTC" as before, reserving "-00" for when
either TZ or the content of TZDEFAULT is invalid.
---
localtime.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/localtime.c b/localtime.c
index f534383b..1c6c1a46 100644
--- a/localtime.c
+++ b/localtime.c
@@ -1484,9 +1484,11 @@ tzset_unlocked(void)
lclptr = sp = malloc(sizeof *lclptr);
# endif
if (sp) {
- if (zoneinit(sp, name, TZLOAD_FROMENV | TZLOAD_TZSTRING) != 0) {
+ int err = zoneinit(sp, name, TZLOAD_FROMENV | TZLOAD_TZSTRING);
+ if (err != 0) {
zoneinit(sp, "", 0);
- strcpy(sp->chars, UNSPEC);
+ if (name || err != ENOENT)
+ strcpy(sp->chars, UNSPEC);
}
if (0 < lcl)
strcpy(lcl_TZname, name);
--
2.48.1
From a06191238f889c517de6c63b8517f85f29d79f4d Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 22 Sep 2025 12:10:50 -0700
Subject: [PROPOSED 2/2] Add commentary on UTC/-00 patch
---
NEWS | 6 ++++++
localtime.c | 2 ++
2 files changed, 8 insertions(+)
diff --git a/NEWS b/NEWS
index 4b5fac51..0ad9b891 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,12 @@ Unreleased, experimental changes
MANFLAGS can override these defaults. (Thanks to G. Branden
Robinson for inspiring these changes.)
+ Changes to code
+
+ An unset TZ is no longer invalid when /etc/localtime is missing,
+ and is abbreviated "UTC" not "-00". This reverts to 2024b behavior.
+ (Problem and patch reported by 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 1c6c1a46..1226e6e0 100644
--- a/localtime.c
+++ b/localtime.c
@@ -1487,6 +1487,8 @@ tzset_unlocked(void)
int err = zoneinit(sp, name, TZLOAD_FROMENV | TZLOAD_TZSTRING);
if (err != 0) {
zoneinit(sp, "", 0);
+ /* Abbreviate with "-00" if there was an error.
+ Do not treat a missing TZDEFAULT file as an error. */
if (name || err != ENOENT)
strcpy(sp->chars, UNSPEC);
}
--
2.48.1