authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-10-06 11:57:23+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-10-06 11:57:23+02:00
log1f7ec0de706eded887bc8dbcf5f45a5546d1be5c
treec651c03cc7623a7feb8f0c6b90ea402f864fb70f
parenta419a1aabce63fedcc77a1118d596864fcff46e3

Address review comments & fix compilation errors


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