authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-18 23:05:51-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:10-08:00
logf27bd87ade2e43dce66963f43ce678e361ddbfc2
tree3b8b56798cb2c913b11ba950efeda8fa0504897c
parent6f00157e1e0159a5115a4e9e2ed389e819499282

std.Io.Threaded: allow length-0 file writes

At first I thought about keeping this as an assertion but I can see this being useful if you already know how many bytes to read and you are filling the end of the buffer. This also more closely mirrors POSIX APIs.

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

lib/std/Io/File.zig+1-3
......@@ -497,7 +497,7 @@ pub fn setTimestampsNow(file: File, io: Io) SetTimestampsError!void {
497497
498498pub const ReadPositionalError = Reader.Error || error{Unseekable};
499499
500/// Returns 0 on end of stream.
500/// Returns 0 on stream end or if `buffer` has no space available for data.
501501///
502502/// See also:
503503/// * `reader`
......@@ -507,8 +507,6 @@ pub fn readPositional(file: File, io: Io, buffer: []const []u8, offset: u64) Rea
507507
508508pub const WritePositionalError = Writer.Error || error{Unseekable};
509509
510/// Returns 0 on end of stream.
511///
512510/// See also:
513511/// * `writer`
514512pub fn writePositional(file: File, io: Io, buffer: []const []const u8, offset: u64) WritePositionalError!usize {
lib/std/Io/Threaded.zig+4
......@@ -6400,6 +6400,7 @@ fn fileReadStreamingPosix(userdata: ?*anyopaque, file: File, data: []const []u8)
64006400 i += 1;
64016401 }
64026402 }
6403 if (i == 0) return 0;
64036404 const dest = iovecs_buffer[0..i];
64046405 assert(dest[0].len > 0);
64056406
......@@ -6482,6 +6483,7 @@ fn fileReadStreamingWindows(userdata: ?*anyopaque, file: File, data: []const []u
64826483 const DWORD = windows.DWORD;
64836484 var index: usize = 0;
64846485 while (data[index].len == 0) index += 1;
6486 if (index == 0) return 0;
64856487 const buffer = data[index];
64866488 const want_read_count: DWORD = @min(std.math.maxInt(DWORD), buffer.len);
64876489
......@@ -6519,6 +6521,7 @@ fn fileReadPositionalPosix(userdata: ?*anyopaque, file: File, data: []const []u8
65196521 i += 1;
65206522 }
65216523 }
6524 if (i == 0) return 0;
65226525 const dest = iovecs_buffer[0..i];
65236526 assert(dest[0].len > 0);
65246527
......@@ -6614,6 +6617,7 @@ fn fileReadPositionalWindows(userdata: ?*anyopaque, file: File, data: []const []
66146617
66156618 var index: usize = 0;
66166619 while (data[index].len == 0) index += 1;
6620 if (index == 0) return 0;
66176621 const buffer = data[index];
66186622 const want_read_count: DWORD = @min(std.math.maxInt(DWORD), buffer.len);
66196623