mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:24:33 +01:00
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:
parent
6f00157e1e
commit
f27bd87ade
2 changed files with 5 additions and 3 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue