authorgravatar for rpkak@noreply.codeberg.orgrpkak <rpkak@noreply.codeberg.org> 2025-08-31 10:56:09+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-09-24 03:50:22+02:00
logbc567312bf58389ffed40f5fc3d0b3ee26271c3e
treed240b4455bf755bd2c9339f39dccbda7dd57152f
parent6069f908e9f1f8655af3faca3bd6de99de58af16
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

use copy_file_range syscall on linux


3 files changed, 10 insertions(+), 6 deletions(-)

lib/std/fs/File.zig+1-1
......@@ -1967,7 +1967,7 @@ pub const Writer = struct {
19671967
19681968 const copy_file_range = switch (native_os) {
19691969 .freebsd => std.os.freebsd.copy_file_range,
1970 .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 {},
1970 .linux => std.os.linux.wrapped.copy_file_range,
19711971 else => {},
19721972 };
19731973 if (@TypeOf(copy_file_range) != void) cfr: {
lib/std/os/linux.zig+3-1
......@@ -9802,7 +9802,9 @@ pub const wrapped = struct {
98029802 };
98039803
98049804 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 {
9805 const rc = system.copy_file_range(fd_in, off_in, fd_out, off_out, len, flags);
9805 const use_c = std.c.versionCheck(if (builtin.abi.isAndroid()) .{ .major = 34, .minor = 0, .patch = 0 } else .{ .major = 2, .minor = 27, .patch = 0 });
9806 const sys = if (use_c) std.c else std.os.linux;
9807 const rc = sys.copy_file_range(fd_in, off_in, fd_out, off_out, len, flags);
98069808 switch (errno(rc)) {
98079809 .SUCCESS => return @intCast(rc),
98089810 .BADF => return error.BadFileFlags,
lib/std/posix.zig+6-4
......@@ -6387,14 +6387,16 @@ pub const CopyFileRangeError = error{
63876387///
63886388/// Maximum offsets on Linux and FreeBSD are `maxInt(i64)`.
63896389pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len: usize, flags: u32) CopyFileRangeError!usize {
6390 if (builtin.os.tag == .freebsd or
6391 (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 })))
6392 {
6390 if (builtin.os.tag == .freebsd or builtin.os.tag == .linux) {
6391 const use_c = native_os != .linux or
6392 std.c.versionCheck(if (builtin.abi.isAndroid()) .{ .major = 34, .minor = 0, .patch = 0 } else .{ .major = 2, .minor = 27, .patch = 0 });
6393 const sys = if (use_c) std.c else linux;
6394
63936395 var off_in_copy: i64 = @bitCast(off_in);
63946396 var off_out_copy: i64 = @bitCast(off_out);
63956397
63966398 while (true) {
6397 const rc = system.copy_file_range(fd_in, &off_in_copy, fd_out, &off_out_copy, len, flags);
6399 const rc = sys.copy_file_range(fd_in, &off_in_copy, fd_out, &off_out_copy, len, flags);
63986400 if (native_os == .freebsd) {
63996401 switch (errno(rc)) {
64006402 .SUCCESS => return @intCast(rc),