diff options
| author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2025-09-23 12:56:11 +0000 |
|---|---|---|
| committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2025-09-23 12:56:11 +0000 |
| commit | a5f14e4f9069a8ffed66d923bb0ecf20d8a0e6af (patch) | |
| tree | b83d927fe269c4c0949432912e976dc3dc87dbbf | |
| parent | 3aac05f56620712744cb57d71a0ef42f8d8e3b52 (diff) | |
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
| -rw-r--r-- | contrib/tzcode/localtime.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/contrib/tzcode/localtime.c b/contrib/tzcode/localtime.c index 15afeeecb6d0..7ba72d730648 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); |
