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 {...@@ -497,7 +497,7 @@ pub fn setTimestampsNow(file: File, io: Io) SetTimestampsError!void {
497497
498pub const ReadPositionalError = Reader.Error || error{Unseekable};498pub 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.
501///501///
502/// See also:502/// See also:
503/// * `reader`503/// * `reader`
...@@ -507,8 +507,6 @@ pub fn readPositional(file: File, io: Io, buffer: []const []u8, offset: u64) Rea...@@ -507,8 +507,6 @@ pub fn readPositional(file: File, io: Io, buffer: []const []u8, offset: u64) Rea
507507
508pub const WritePositionalError = Writer.Error || error{Unseekable};508pub const WritePositionalError = Writer.Error || error{Unseekable};
509509
510/// Returns 0 on end of stream.
511///
512/// See also:510/// See also:
513/// * `writer`511/// * `writer`
514pub fn writePositional(file: File, io: Io, buffer: []const []const u8, offset: u64) WritePositionalError!usize {512pub 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)...@@ -6400,6 +6400,7 @@ fn fileReadStreamingPosix(userdata: ?*anyopaque, file: File, data: []const []u8)
6400 i += 1;6400 i += 1;
6401 }6401 }
6402 }6402 }
6403 if (i == 0) return 0;
6403 const dest = iovecs_buffer[0..i];6404 const dest = iovecs_buffer[0..i];
6404 assert(dest[0].len > 0);6405 assert(dest[0].len > 0);
64056406
...@@ -6482,6 +6483,7 @@ fn fileReadStreamingWindows(userdata: ?*anyopaque, file: File, data: []const []u...@@ -6482,6 +6483,7 @@ fn fileReadStreamingWindows(userdata: ?*anyopaque, file: File, data: []const []u
6482 const DWORD = windows.DWORD;6483 const DWORD = windows.DWORD;
6483 var index: usize = 0;6484 var index: usize = 0;
6484 while (data[index].len == 0) index += 1;6485 while (data[index].len == 0) index += 1;
6486 if (index == 0) return 0;
6485 const buffer = data[index];6487 const buffer = data[index];
6486 const want_read_count: DWORD = @min(std.math.maxInt(DWORD), buffer.len);6488 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...@@ -6519,6 +6521,7 @@ fn fileReadPositionalPosix(userdata: ?*anyopaque, file: File, data: []const []u8
6519 i += 1;6521 i += 1;
6520 }6522 }
6521 }6523 }
6524 if (i == 0) return 0;
6522 const dest = iovecs_buffer[0..i];6525 const dest = iovecs_buffer[0..i];
6523 assert(dest[0].len > 0);6526 assert(dest[0].len > 0);
65246527
...@@ -6614,6 +6617,7 @@ fn fileReadPositionalWindows(userdata: ?*anyopaque, file: File, data: []const []...@@ -6614,6 +6617,7 @@ fn fileReadPositionalWindows(userdata: ?*anyopaque, file: File, data: []const []
66146617
6615 var index: usize = 0;6618 var index: usize = 0;
6616 while (data[index].len == 0) index += 1;6619 while (data[index].len == 0) index += 1;
6620 if (index == 0) return 0;
6617 const buffer = data[index];6621 const buffer = data[index];
6618 const want_read_count: DWORD = @min(std.math.maxInt(DWORD), buffer.len);6622 const want_read_count: DWORD = @min(std.math.maxInt(DWORD), buffer.len);
66196623