Thanks for reporting the bug and the POSIX versions. zic should work even on POSIX.1-2001 platforms, so I installed the attached. This should let zic work even on unmodified NetBSD.

From 9c772ca79952c0a61cf209c4068ff586d5c4ba6e Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Thu, 18 Dec 2025 09:21:00 -0800
Subject: [PROPOSED] Port to POSIX.1-2001 fflush
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Problem on NetBSD reported by Christos Zoulas in:
https://lists.iana.org/hyperkitty/list/[email protected]/thread/I4CHNIVPXFXVISCGCJMW4OHD4N7O3PTQ/
* NEWS: Mention this.
* zic.c (close_file): Call fflush only if tempname is nonnull.
As Jonathan Wakely pointed out in the above-cited thread,
the requirement that fflush succeed on read-only streams
was added in POSIX.1-2008, and NetBSD’s fflush conforms only
to POSIX.1-2001 in this department.  Ironically, the fflush
was put in only to port to non-POSIX platforms where you can’t
write to a file after chmodding it to be read-only.
---
 NEWS  | 3 +++
 zic.c | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 2ae02d59..96df4782 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@ Unreleased, experimental changes
     This occurs in tzdata only in Asia/Tbilisi on 1997-03-30.
     (Thanks to Renchunhui for a test case showing the bug.)
 
+    zic no longer assumes you can fflush a read-only stream.
+    (Problem reported by Christos Zoulas.)
+
 
 Release 2025c - 2025-12-10 14:42:37 -0800
 
diff --git a/zic.c b/zic.c
index 163eefa8..12854c43 100644
--- a/zic.c
+++ b/zic.c
@@ -814,8 +814,8 @@ close_file(FILE *stream, char const *dir, char const *name,
 	   char const *tempname)
 {
   char const *e = (ferror(stream) ? _("I/O error")
-		   : (fflush(stream) < 0
-		      || (tempname && chmetadata(stream) < 0)
+		   : ((tempname
+		       && (fflush(stream) < 0 || chmetadata(stream) < 0))
 		      || fclose(stream) < 0)
 		   ? strerror(errno) : NULL);
   if (e) {
-- 
2.51.0

Reply via email to