From 1f7ec0de706eded887bc8dbcf5f45a5546d1be5c Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 6 Oct 2020 11:57:23 +0200 Subject: [PATCH] Address review comments & fix compilation errors --- lib/std/fs.zig | 18 +++++++++--------- lib/std/os.zig | 14 +++++++------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 92f68590f9..6b4f9384dd 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -2270,14 +2270,14 @@ const CopyFileError = error{SystemResources} || os.CopyFileRangeError || os.Send fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void { if (comptime std.Target.current.isDarwin()) { const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE_DATA); - switch (errno(rc)) { + switch (os.errno(rc)) { 0 => return, - EINVAL => unreachable, - ENOMEM => return error.SystemResources, - // The source file was not a directory, symbolic link, or regular file. + os.EINVAL => unreachable, + os.ENOMEM => return error.SystemResources, + // The source file is not a directory, symbolic link, or regular file. // Try with the fallback path before giving up. - ENOTSUP => {}, - else => |err| return unexpectedErrno(err), + os.ENOTSUP => {}, + else => |err| return os.unexpectedErrno(err), } } @@ -2286,9 +2286,9 @@ fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void { // most efficient method (if available). var offset: u64 = 0; cfr_loop: while (true) { - // The kernel checks `offset+count` for overflow, use a 32 bit - // value so that the syscall won't return EINVAL except for - // impossibly large files. + // The kernel checks the u64 value `offset+count` for overflow, use + // a 32 bit value so that the syscall won't return EINVAL except for + // impossibly large files (> 2^64-1 - 2^32-1). const amt = try os.copy_file_range(fd_in, offset, fd_out, offset, math.maxInt(u32), 0); // Terminate when no data was copied if (amt == 0) break :cfr_loop; diff --git a/lib/std/os.zig b/lib/std/os.zig index e4e0b1d4a1..0e81b73f8c 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -4954,6 +4954,11 @@ pub const CopyFileRangeError = error{ FileBusy, } || PReadError || PWriteError || UnexpectedError; +var has_copy_file_range_syscall = init: { + const kernel_has_syscall = comptime std.Target.current.os.isAtLeast(.linux, .{ .major = 4, .minor = 5 }) orelse true; + break :init std.atomic.Int(bool).init(kernel_has_syscall); +}; + /// Transfer data between file descriptors at specified offsets. /// Returns the number of bytes written, which can less than requested. /// @@ -4979,16 +4984,11 @@ pub const CopyFileRangeError = error{ /// Other systems fall back to calling `pread` / `pwrite`. /// /// Maximum offsets on Linux are `math.maxInt(i64)`. -var has_copy_file_range_syscall = init: { - const kernel_has_syscall = comptime std.Target.current.os.isAtLeast(.linux, .{ .major = 4, .minor = 5 }) orelse true; - break :init std.atomic.Int(u1).init(@boolToInt(kernel_has_syscall)); -}; - 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 { const use_c = std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok; if (std.Target.current.os.tag == .linux and - (use_c or has_copy_file_range_syscall.get() != 0)) + (use_c or has_copy_file_range_syscall.get())) { const sys = if (use_c) std.c else linux; @@ -5013,7 +5013,7 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len EXDEV => {}, // syscall added in Linux 4.5, use fallback ENOSYS => { - has_copy_file_range_syscall.set(0); + has_copy_file_range_syscall.set(false); }, else => |err| return unexpectedErrno(err), }