Skip to content

Commit b5b0cb4

Browse files
rpkakalexrp
authored andcommitted
use copy_file_range syscall on linux
1 parent 32a34b6 commit b5b0cb4

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

lib/std/fs/File.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,7 @@ pub const Writer = struct {
19141914

19151915
const copy_file_range = switch (native_os) {
19161916
.freebsd => std.os.freebsd.copy_file_range,
1917-
.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 {},
1917+
.linux => std.os.linux.wrapped.copy_file_range,
19181918
else => {},
19191919
};
19201920
if (@TypeOf(copy_file_range) != void) cfr: {

lib/std/os/linux.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6468,14 +6468,16 @@ pub const CopyFileRangeError = error{
64686468
///
64696469
/// Maximum offsets on Linux and FreeBSD are `maxInt(i64)`.
64706470
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 {
6471-
if (builtin.os.tag == .freebsd or
6472-
(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 })))
6473-
{
6471+
if (builtin.os.tag == .freebsd or builtin.os.tag == .linux) {
6472+
const use_c = native_os != .linux or
6473+
std.c.versionCheck(if (builtin.abi.isAndroid()) .{ .major = 34, .minor = 0, .patch = 0 } else .{ .major = 2, .minor = 27, .patch = 0 });
6474+
const sys = if (use_c) std.c else linux;
6475+
64746476
var off_in_copy: i64 = @bitCast(off_in);
64756477
var off_out_copy: i64 = @bitCast(off_out);
64766478

64776479
while (true) {
6478-
const rc = system.copy_file_range(fd_in, &off_in_copy, fd_out, &off_out_copy, len, flags);
6480+
const rc = sys.copy_file_range(fd_in, &off_in_copy, fd_out, &off_out_copy, len, flags);
64796481
if (native_os == .freebsd) {
64806482
switch (errno(rc)) {
64816483
.SUCCESS => return @intCast(rc),

0 commit comments

Comments
 (0)