zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit bc567312bf58389ffed40f5fc3d0b3ee26271c3e (tree)
parent 6069f908e9f1f8655af3faca3bd6de99de58af16
Author: rpkak <rpkak@users.noreply.github.com>
Date:   Sun, 31 Aug 2025 10:56:09 +0200

use copy_file_range syscall on linux

Diffstat:
Mlib/std/fs/File.zig | 2+-
Mlib/std/os/linux.zig | 4+++-
Mlib/std/posix.zig | 10++++++----
3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/std/fs/File.zig b/lib/std/fs/File.zig @@ -1967,7 +1967,7 @@ pub const Writer = struct { const copy_file_range = switch (native_os) { .freebsd => std.os.freebsd.copy_file_range, - .linux => if (std.c.versionCheck(if (builtin.abi.isAndroid()) .{ .major = 34, .minor = 0, .patch = 0 } else .{ .major = 2, .minor = 27, .patch = 0 })) std.os.linux.wrapped.copy_file_range else {}, + .linux => std.os.linux.wrapped.copy_file_range, else => {}, }; if (@TypeOf(copy_file_range) != void) cfr: { diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig @@ -9802,7 +9802,9 @@ pub const wrapped = struct { }; pub fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: u32) CopyFileRangeError!usize { - const rc = system.copy_file_range(fd_in, off_in, fd_out, off_out, len, flags); + const use_c = std.c.versionCheck(if (builtin.abi.isAndroid()) .{ .major = 34, .minor = 0, .patch = 0 } else .{ .major = 2, .minor = 27, .patch = 0 }); + const sys = if (use_c) std.c else std.os.linux; + const rc = sys.copy_file_range(fd_in, off_in, fd_out, off_out, len, flags); switch (errno(rc)) { .SUCCESS => return @intCast(rc), .BADF => return error.BadFileFlags, diff --git a/lib/std/posix.zig b/lib/std/posix.zig @@ -6387,14 +6387,16 @@ pub const CopyFileRangeError = error{ /// /// Maximum offsets on Linux and FreeBSD are `maxInt(i64)`. pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len: usize, flags: u32) CopyFileRangeError!usize { - if (builtin.os.tag == .freebsd or - (comptime builtin.os.tag == .linux and std.c.versionCheck(if (builtin.abi.isAndroid()) .{ .major = 34, .minor = 0, .patch = 0 } else .{ .major = 2, .minor = 27, .patch = 0 }))) - { + if (builtin.os.tag == .freebsd or builtin.os.tag == .linux) { + const use_c = native_os != .linux or + std.c.versionCheck(if (builtin.abi.isAndroid()) .{ .major = 34, .minor = 0, .patch = 0 } else .{ .major = 2, .minor = 27, .patch = 0 }); + const sys = if (use_c) std.c else linux; + var off_in_copy: i64 = @bitCast(off_in); var off_out_copy: i64 = @bitCast(off_out); while (true) { - const rc = system.copy_file_range(fd_in, &off_in_copy, fd_out, &off_out_copy, len, flags); + const rc = sys.copy_file_range(fd_in, &off_in_copy, fd_out, &off_out_copy, len, flags); if (native_os == .freebsd) { switch (errno(rc)) { .SUCCESS => return @intCast(rc),