feature. See also
. The project being documented here (as the example) is the Zig library itself.
Dispatch.fileReadPositional
fn fileReadPositional(
userdata: ?*anyopaque,
file: File,
data: []const []u8,
offset: u64,
) File.ReadPositionalError!usize
File
Code
fn fileReadPositional(
userdata: ?*anyopaque,
file: File,
data: []const []u8,
offset: u64,
) File.ReadPositionalError!usize {
const ev: *Evented = @ptrCast(@alignCast(userdata));
_ = ev;
var iovecs: [max_iovecs_len]iovec = undefined;
var iovlen: iovlen_t = 0;
var remaining: Io.Limit = .unlimited;
for (data) |buf| addBuf(false, &iovecs, &iovlen, &remaining, buf);
if (iovlen == 0) return 0;
while (true) {
const rc = c.preadv(file.handle, &iovecs, iovlen, @bitCast(offset));
switch (c.errno(rc)) {
.SUCCESS => return @intCast(rc),
.INTR => {},
.NXIO => return error.Unseekable,
.SPIPE => return error.Unseekable,
.OVERFLOW => return error.Unseekable,
.NOBUFS => return error.SystemResources,
.NOMEM => return error.SystemResources,
.AGAIN => return error.WouldBlock,
.IO => return error.InputOutput,
.ISDIR => return error.IsDir,
.NOTCONN => |err| return errnoBug(err),
.CONNRESET => |err| return errnoBug(err),
.INVAL => |err| return errnoBug(err),
.FAULT => |err| return errnoBug(err),
.BADF => return error.NotOpenForReading,
else => |err| return unexpectedErrno(err),
}
}
}