mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-07 14:24:43 +00:00
Address review comments & fix compilation errors
This commit is contained in:
parent
a419a1aabc
commit
1f7ec0de70
2 changed files with 16 additions and 16 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue