| author | |
| committer | |
| log | 1f7ec0de706eded887bc8dbcf5f45a5546d1be5c |
| tree | c651c03cc7623a7feb8f0c6b90ea402f864fb70f |
| parent | a419a1aabce63fedcc77a1118d596864fcff46e3 |
2 files changed, 16 insertions(+), 16 deletions(-)
lib/std/fs.zig+9-9| ... | ... | @@ -2270,14 +2270,14 @@ const CopyFileError = error{SystemResources} || os.CopyFileRangeError || os.Send |
| 2270 | 2270 | fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void { |
| 2271 | 2271 | if (comptime std.Target.current.isDarwin()) { |
| 2272 | 2272 | const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE_DATA); |
| 2273 | switch (errno(rc)) { | |
| 2273 | switch (os.errno(rc)) { | |
| 2274 | 2274 | 0 => return, |
| 2275 | EINVAL => unreachable, | |
| 2276 | ENOMEM => return error.SystemResources, | |
| 2277 | // The source file was not a directory, symbolic link, or regular file. | |
| 2275 | os.EINVAL => unreachable, | |
| 2276 | os.ENOMEM => return error.SystemResources, | |
| 2277 | // The source file is not a directory, symbolic link, or regular file. | |
| 2278 | 2278 | // Try with the fallback path before giving up. |
| 2279 | ENOTSUP => {}, | |
| 2280 | else => |err| return unexpectedErrno(err), | |
| 2279 | os.ENOTSUP => {}, | |
| 2280 | else => |err| return os.unexpectedErrno(err), | |
| 2281 | 2281 | } |
| 2282 | 2282 | } |
| 2283 | 2283 | |
| ... | ... | @@ -2286,9 +2286,9 @@ fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void { |
| 2286 | 2286 | // most efficient method (if available). |
| 2287 | 2287 | var offset: u64 = 0; |
| 2288 | 2288 | cfr_loop: while (true) { |
| 2289 | // The kernel checks `offset+count` for overflow, use a 32 bit | |
| 2290 | // value so that the syscall won't return EINVAL except for | |
| 2291 | // impossibly large files. | |
| 2289 | // The kernel checks the u64 value `offset+count` for overflow, use | |
| 2290 | // a 32 bit value so that the syscall won't return EINVAL except for | |
| 2291 | // impossibly large files (> 2^64-1 - 2^32-1). | |
| 2292 | 2292 | const amt = try os.copy_file_range(fd_in, offset, fd_out, offset, math.maxInt(u32), 0); |
| 2293 | 2293 | // Terminate when no data was copied |
| 2294 | 2294 | if (amt == 0) break :cfr_loop; |
lib/std/os.zig+7-7| ... | ... | @@ -4954,6 +4954,11 @@ pub const CopyFileRangeError = error{ |
| 4954 | 4954 | FileBusy, |
| 4955 | 4955 | } || PReadError || PWriteError || UnexpectedError; |
| 4956 | 4956 | |
| 4957 | var has_copy_file_range_syscall = init: { | |
| 4958 | const kernel_has_syscall = comptime std.Target.current.os.isAtLeast(.linux, .{ .major = 4, .minor = 5 }) orelse true; | |
| 4959 | break :init std.atomic.Int(bool).init(kernel_has_syscall); | |
| 4960 | }; | |
| 4961 | ||
| 4957 | 4962 | /// Transfer data between file descriptors at specified offsets. |
| 4958 | 4963 | /// Returns the number of bytes written, which can less than requested. |
| 4959 | 4964 | /// |
| ... | ... | @@ -4979,16 +4984,11 @@ pub const CopyFileRangeError = error{ |
| 4979 | 4984 | /// Other systems fall back to calling `pread` / `pwrite`. |
| 4980 | 4985 | /// |
| 4981 | 4986 | /// Maximum offsets on Linux are `math.maxInt(i64)`. |
| 4982 | var has_copy_file_range_syscall = init: { | |
| 4983 | const kernel_has_syscall = comptime std.Target.current.os.isAtLeast(.linux, .{ .major = 4, .minor = 5 }) orelse true; | |
| 4984 | break :init std.atomic.Int(u1).init(@boolToInt(kernel_has_syscall)); | |
| 4985 | }; | |
| 4986 | ||
| 4987 | 4987 | 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 { |
| 4988 | 4988 | const use_c = std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok; |
| 4989 | 4989 | |
| 4990 | 4990 | if (std.Target.current.os.tag == .linux and |
| 4991 | (use_c or has_copy_file_range_syscall.get() != 0)) | |
| 4991 | (use_c or has_copy_file_range_syscall.get())) | |
| 4992 | 4992 | { |
| 4993 | 4993 | const sys = if (use_c) std.c else linux; |
| 4994 | 4994 | |
| ... | ... | @@ -5013,7 +5013,7 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len |
| 5013 | 5013 | EXDEV => {}, |
| 5014 | 5014 | // syscall added in Linux 4.5, use fallback |
| 5015 | 5015 | ENOSYS => { |
| 5016 | has_copy_file_range_syscall.set(0); | |
| 5016 | has_copy_file_range_syscall.set(false); | |
| 5017 | 5017 | }, |
| 5018 | 5018 | else => |err| return unexpectedErrno(err), |
| 5019 | 5019 | } |