authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 23:44:38-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 23:46:43-08:00
logace08ba642361d57268b1f102c371b060a1f9a2c
treedd32ca5898cee7afe81b6139b32df398514b1448
parenta901e9241396a11f807bf40bbd548e25f120deab

std.Io.Threaded: prevent 0-byte file writes

these cause EINVAL on darwin and are generally a wasted syscall. and remove a bogus error from File.Writer.Error.

2 files changed, 6 insertions(+), 3 deletions(-)

lib/std/Io/File/Writer.zig-1
......@@ -26,7 +26,6 @@ pub const Error = error{
2626 InputOutput,
2727 NoSpaceLeft,
2828 DeviceBusy,
29 InvalidArgument,
3029 /// File descriptor does not hold the required rights to write to it.
3130 AccessDenied,
3231 PermissionDenied,
lib/std/Io/Threaded.zig+6-2
......@@ -7449,6 +7449,8 @@ fn fileWritePositional(
74497449 },
74507450 };
74517451
7452 if (iovlen == 0) return 0;
7453
74527454 if (native_os == .wasi and !builtin.link_libc) {
74537455 var n_written: usize = undefined;
74547456 try current_thread.beginSyscall();
......@@ -7502,7 +7504,7 @@ fn fileWritePositional(
75027504 else => |e| {
75037505 current_thread.endSyscall();
75047506 switch (e) {
7505 .INVAL => return error.InvalidArgument,
7507 .INVAL => |err| return errnoBug(err),
75067508 .FAULT => |err| return errnoBug(err),
75077509 .AGAIN => return error.WouldBlock,
75087510 .BADF => return error.NotOpenForWriting, // Usually a race condition.
......@@ -7569,6 +7571,8 @@ fn fileWriteStreaming(
75697571 },
75707572 };
75717573
7574 if (iovlen == 0) return 0;
7575
75727576 if (native_os == .wasi and !builtin.link_libc) {
75737577 var n_written: usize = undefined;
75747578 try current_thread.beginSyscall();
......@@ -7619,7 +7623,7 @@ fn fileWriteStreaming(
76197623 else => |e| {
76207624 current_thread.endSyscall();
76217625 switch (e) {
7622 .INVAL => return error.InvalidArgument,
7626 .INVAL => |err| return errnoBug(err),
76237627 .FAULT => |err| return errnoBug(err),
76247628 .AGAIN => return error.WouldBlock,
76257629 .BADF => return error.NotOpenForWriting, // Can be a race condition.