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
22702270fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void {
22712271 if (comptime std.Target.current.isDarwin()) {
22722272 const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE_DATA);
2273 switch (errno(rc)) {
2273 switch (os.errno(rc)) {
22742274 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.
22782278 // 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),
22812281 }
22822282 }
22832283
......@@ -2286,9 +2286,9 @@ fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void {
22862286 // most efficient method (if available).
22872287 var offset: u64 = 0;
22882288 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).
22922292 const amt = try os.copy_file_range(fd_in, offset, fd_out, offset, math.maxInt(u32), 0);
22932293 // Terminate when no data was copied
22942294 if (amt == 0) break :cfr_loop;
lib/std/os.zig+7-7
......@@ -4954,6 +4954,11 @@ pub const CopyFileRangeError = error{
49544954 FileBusy,
49554955} || 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
49574962/// Transfer data between file descriptors at specified offsets.
49584963/// Returns the number of bytes written, which can less than requested.
49594964///
......@@ -4979,16 +4984,11 @@ pub const CopyFileRangeError = error{
49794984/// Other systems fall back to calling `pread` / `pwrite`.
49804985///
49814986/// 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
49874987pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len: usize, flags: u32) CopyFileRangeError!usize {
49884988 const use_c = std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok;
49894989
49904990 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()))
49924992 {
49934993 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
50135013 EXDEV => {},
50145014 // syscall added in Linux 4.5, use fallback
50155015 ENOSYS => {
5016 has_copy_file_range_syscall.set(0);
5016 has_copy_file_range_syscall.set(false);
50175017 },
50185018 else => |err| return unexpectedErrno(err),
50195019 }