From a5f14e4f9069a8ffed66d923bb0ecf20d8a0e6af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Tue, 23 Sep 2025 14:56:11 +0200 Subject: [PATCH] tzcode: Use -00 only for invalid time zones As of tzcode 2025a, if we are unable to load a time zone, we set tzname to "-00" to indicate an error. This penalizes users who simply don't set TZ or create /etc/localtime as a faster way of setting the time zone to UTC (pointing /etc/localtime at /usr/share/zoneinfo/UTC forces us to parse it every time for no real benefit). To rectify this, use "-00" only if TZ was set or zoneinit() returned something else than ENOENT. MFC after: 3 days Fixes: 967a49a21a27 ("Update tzcode to 2025b") Reviewed by: philip Differential Revision: https://reviews.freebsd.org/D52680 --- contrib/tzcode/localtime.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/contrib/tzcode/localtime.c b/contrib/tzcode/localtime.c index 15afeeecb6d..7ba72d73064 100644 --- a/contrib/tzcode/localtime.c +++ b/contrib/tzcode/localtime.c @@ -1649,9 +1649,13 @@ tzset_unlocked_name(char const *name) 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); + /* 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); } if (0 < lcl) strcpy(lcl_TZname, name);