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.
This commit is contained in:
Andrew Kelley 2025-12-18 23:05:51 -08:00
parent 6f00157e1e
commit f27bd87ade
2 changed files with 5 additions and 3 deletions

View file

@ -497,7 +497,7 @@ pub fn setTimestampsNow(file: File, io: Io) SetTimestampsError!void {
pub const ReadPositionalError = Reader.Error || error{Unseekable};
/// Returns 0 on end of stream.
/// Returns 0 on stream end or if `buffer` has no space available for data.
///
/// See also:
/// * `reader`
@ -507,8 +507,6 @@ pub fn readPositional(file: File, io: Io, buffer: []const []u8, offset: u64) Rea
pub const WritePositionalError = Writer.Error || error{Unseekable};
/// Returns 0 on end of stream.
///
/// See also:
/// * `writer`
pub fn writePositional(file: File, io: Io, buffer: []const []const u8, offset: u64) WritePositionalError!usize {

View file

@ -6400,6 +6400,7 @@ fn fileReadStreamingPosix(userdata: ?*anyopaque, file: File, data: []const []u8)
i += 1;
}
}
if (i == 0) return 0;
const dest = iovecs_buffer[0..i];
assert(dest[0].len > 0);
@ -6482,6 +6483,7 @@ fn fileReadStreamingWindows(userdata: ?*anyopaque, file: File, data: []const []u
const DWORD = windows.DWORD;
var index: usize = 0;
while (data[index].len == 0) index += 1;
if (index == 0) return 0;
const buffer = data[index];
const want_read_count: DWORD = @min(std.math.maxInt(DWORD), buffer.len);
@ -6519,6 +6521,7 @@ fn fileReadPositionalPosix(userdata: ?*anyopaque, file: File, data: []const []u8
i += 1;
}
}
if (i == 0) return 0;
const dest = iovecs_buffer[0..i];
assert(dest[0].len > 0);
@ -6614,6 +6617,7 @@ fn fileReadPositionalWindows(userdata: ?*anyopaque, file: File, data: []const []
var index: usize = 0;
while (data[index].len == 0) index += 1;
if (index == 0) return 0;
const buffer = data[index];
const want_read_count: DWORD = @min(std.math.maxInt(DWORD), buffer.len);