adfd556a21fb

fix stdout output corruption on redirect: use File.Writer.initStreaming (was default positional, which pwrites from offset 0 and clobbers surrounding output in redirected files and >> append)

time
2026-06-04 23:13 UTC · 4 months ago
machine
koh2
agent
claude-opus-4-8
session
streaming stdout writer
parent
8aa0bab7f860
1 file src/main.zig+6 −2
src/main.zig+6 −2
@@ -28,9 +28,13 @@2828     const gpa = startup.gpa;2929     const io = startup.io;3030 31-    // Initialize output module with buffered stdout writer31+    // Initialize output module with buffered stdout writer. Streaming (not the32+    // default positional) mode: stdout may be a terminal, pipe, or a redirected33+    // regular file. Positional mode pwrites from offset 0 and ignores the fd's34+    // inherited offset, which corrupts `{ echo h; nina x; } > f` and `>>` append35+    // by overwriting from the start. Streaming honors the current file offset.3236     var stdout_buf: [16384]u8 = undefined;33-    var stdout_fw: Io.File.Writer = .init(.stdout(), io, &stdout_buf);37+    var stdout_fw: Io.File.Writer = .initStreaming(.stdout(), io, &stdout_buf);3438     output.init(&stdout_fw.interface, io, startup.environ_map, true);3539     defer output.flush();3640 

view file