Files
zig/lib/c/fcntl.zig
David Senoner 21914c7c01 ziglibc: migrate tee linux syscall (#31911)
Add the Linux syscall wrapper for `tee`.

Migrate the `tee` syscall from musl libc to zig libc.

langref: note `ssize_t` and `isize`  are ABI compatible

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31911
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: David Senoner <seda18@rolmail.net>
Co-committed-by: David Senoner <seda18@rolmail.net>
2026-04-18 07:30:43 +02:00

34 lines
1.0 KiB
Zig

const builtin = @import("builtin");
const std = @import("std");
const linux = std.os.linux;
const off_t = linux.off_t;
const symbol = @import("../c.zig").symbol;
const errno = @import("../c.zig").errno;
comptime {
if (builtin.target.isMuslLibC()) {
symbol(&fallocateLinux, "fallocate");
symbol(&posix_fadviseLinux, "posix_fadvise");
symbol(&posix_fallocateLinux, "posix_fallocate");
symbol(&teeLinux, "tee");
}
}
fn fallocateLinux(fd: c_int, mode: c_int, offset: off_t, len: off_t) callconv(.c) c_int {
return errno(linux.fallocate(fd, @bitCast(mode), offset, len));
}
fn posix_fadviseLinux(fd: c_int, offset: off_t, len: off_t, advice: c_int) callconv(.c) c_int {
return errno(linux.fadvise(fd, offset, len, @intCast(advice)));
}
fn posix_fallocateLinux(fd: c_int, offset: off_t, len: off_t) callconv(.c) c_int {
return errno(linux.fallocate(fd, 0, offset, len));
}
fn teeLinux(src: c_int, dest: c_int, len: usize, flags: c_uint) callconv(.c) isize {
return errno(linux.tee(src, dest, len, flags));
}