Function sendfile [src]
Prototype
pub fn sendfile( out_fd: fd_t, in_fd: fd_t, in_offset: ?*off_t, in_len: usize, ) SendfileError!usize Parameters
out_fd: fd_tin_fd: fd_tin_offset: ?*off_tin_len: usize Possible Errors
out_fd is an unconnected socket, or out_fd closed its read end.
Unspecified error while reading from in_fd.
Insufficient kernel memory to read from in_fd.
The Operating System returned an undocumented error code.
This error is in theory not possible, but it would be better to handle this error than to invoke undefined behavior.
When this error code is observed, it usually means the Zig Standard Library needs a small patch to add the error code to the error set for the respective function.
offset is not null but the input file is not seekable.
Descriptor is not valid or locked, or an mmap(2)-like operation is not available for in_fd.
Nonblocking I/O has been selected but the write would block.
Source
pub fn sendfile(
out_fd: fd_t,
in_fd: fd_t,
in_offset: ?*off_t,
in_len: usize,
) SendfileError!usize {
const adjusted_len = @min(in_len, 0x7ffff000); // Prevents EOVERFLOW.
const sendfileSymbol = if (lfs64_abi) system.sendfile64 else system.sendfile;
const rc = sendfileSymbol(out_fd, in_fd, in_offset, adjusted_len);
switch (errno(rc)) {
.SUCCESS => return @intCast(rc),
.BADF => return invalidApiUsage(), // Always a race condition.
.FAULT => return invalidApiUsage(), // Segmentation fault.
.OVERFLOW => return unexpectedErrno(.OVERFLOW), // We avoid passing too large of a `count`.
.NOTCONN => return error.BrokenPipe, // `out_fd` is an unconnected socket
.INVAL => return error.UnsupportedOperation,
.AGAIN => return error.WouldBlock,
.IO => return error.InputOutput,
.PIPE => return error.BrokenPipe,
.NOMEM => return error.SystemResources,
.NXIO => return error.Unseekable,
.SPIPE => return error.Unseekable,
else => |err| return unexpectedErrno(err),
}
}