On 2024-12-08 23:52, Paul Eggert wrote:
I suspect we'll need to distinguish 'zdump "-"' (where reading from stdin could be useful) from TZ="-" (where we surely don't want a program to read from standard input merely because it wants the time of day and someone used a squirrelly TZ string).

I did that by installing the attached proposed further patch.
From 24a4d97fc0efbeb97d6c53201fec1a554f7e27e5 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 9 Dec 2024 13:26:00 -0800
Subject: [PROPOSED] 'zdump -' now reads from stdin

This is from a question by Arthur David Olson in:
https://lists.iana.org/hyperkitty/list/[email protected]/message/P2A7IDLJ3QQRRBVX7B5XOHPGNRWBELB5/
* NEWS, zdump.8: Mention this.
* zdump.c (main): Implement it.
---
 NEWS    | 3 +++
 zdump.8 | 7 +++++++
 zdump.c | 6 +++++-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index bf560e21..7f22b9c1 100644
--- a/NEWS
+++ b/NEWS
@@ -65,6 +65,9 @@ Unreleased, experimental changes
     platform has O_CLOFORK and O_CLOEXEC respectively.  Also, the
     functions no longer let a TZif file become a controlling terminal.
 
+    'zdump -' now reads TZif data from /dev/stdin.
+    (From a question by Arthur David Olson.)
+
   Changes to documentation
 
     The name Etc/Unknown is now reserved: it will not be used by TZDB.
diff --git a/zdump.8 b/zdump.8
index 38dd8614..8792b54e 100644
--- a/zdump.8
+++ b/zdump.8
@@ -25,6 +25,13 @@ The
 program prints the current time in each
 .I timezone
 named on the command line.
+A
+.I timezone
+of
+.B \*-
+is treated as if it were /dev/stdin;
+this can be used to pipe TZif data into
+.BR zdump .
 .SH OPTIONS
 .TP
 .B \*-\*-version
diff --git a/zdump.c b/zdump.c
index ea051adf..8e836e60 100644
--- a/zdump.c
+++ b/zdump.c
@@ -582,7 +582,11 @@ main(int argc, char *argv[])
 	longest = min(arglenmax, INT_MAX - 2);
 
 	for (i = optind; i < argc; ++i) {
-		timezone_t tz = tzalloc(argv[i]);
+		/* Treat "-" as standard input on platforms with /dev/stdin.
+		   It's not worth the bother of supporting "-" on other
+		   platforms, as that would need temp files.  */
+		timezone_t tz = tzalloc(strcmp(argv[i], "-") == 0
+					? "/dev/stdin" : argv[i]);
 		char const *ab;
 		time_t t;
 		struct tm tm, newtm;
-- 
2.47.1

Reply via email to