From 108a51b11032ba3ed7864a653f87283853e6e318 Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Thu, 29 Aug 2019 10:34:05 +0200 Subject: [PATCH] fix issues with debug.zig - Use sys_*stat*64 instead of sys_*stat* where appropriate - Fix overflow when calculating atime, ctime and mtime on File.stat() - Fix compilation error casting getEndPos to usize. --- std/debug.zig | 2 +- std/fs/file.zig | 6 +++--- std/os/bits/linux/arm-eabi.zig | 4 ++-- std/os/linux.zig | 24 ++++++++++++++++++++---- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/std/debug.zig b/std/debug.zig index d1c17343ef..a6ef60b663 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -1053,7 +1053,7 @@ fn openSelfDebugInfoPosix(allocator: *mem.Allocator) !DwarfInfo { S.self_exe_file = try fs.openSelfExe(); errdefer S.self_exe_file.close(); - const self_exe_mmap_len = mem.alignForward(try S.self_exe_file.getEndPos(), mem.page_size); + const self_exe_mmap_len = mem.alignForward(@intCast(usize, try S.self_exe_file.getEndPos()), mem.page_size); const self_exe_mmap = try os.mmap( null, self_exe_mmap_len, diff --git a/std/fs/file.zig b/std/fs/file.zig index 0014693d40..83cbe23780 100644 --- a/std/fs/file.zig +++ b/std/fs/file.zig @@ -261,9 +261,9 @@ pub const File = struct { return Stat{ .size = @bitCast(u64, st.size), .mode = st.mode, - .atime = atime.tv_sec * std.time.ns_per_s + atime.tv_nsec, - .mtime = mtime.tv_sec * std.time.ns_per_s + mtime.tv_nsec, - .ctime = ctime.tv_sec * std.time.ns_per_s + ctime.tv_nsec, + .atime = @intCast(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec, + .mtime = @intCast(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec, + .ctime = @intCast(i64, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec, }; } diff --git a/std/os/bits/linux/arm-eabi.zig b/std/os/bits/linux/arm-eabi.zig index 1b45588459..5048a2afc7 100644 --- a/std/os/bits/linux/arm-eabi.zig +++ b/std/os/bits/linux/arm-eabi.zig @@ -502,7 +502,7 @@ pub const msghdr_const = extern struct { /// methods to accomplish this. pub const Stat = extern struct { dev: u64, - __dev_patting: u32, + __dev_padding: u32, __ino_truncated: u32, mode: u32, nlink: u32, @@ -512,7 +512,7 @@ pub const Stat = extern struct { __rdev_padding: u32, size: i64, blksize: i32, - blocks: i64, + blocks: u64, atim: timespec, mtim: timespec, ctim: timespec, diff --git a/std/os/linux.zig b/std/os/linux.zig index 7d019001ef..3134ebf641 100644 --- a/std/os/linux.zig +++ b/std/os/linux.zig @@ -713,22 +713,38 @@ pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: } pub fn fstat(fd: i32, stat_buf: *Stat) usize { - return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf)); + if (@hasDecl(@This(), "SYS_fstat64")) { + return syscall2(SYS_fstat64, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf)); + } else { + return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf)); + } } // TODO https://github.com/ziglang/zig/issues/265 pub fn stat(pathname: [*]const u8, statbuf: *Stat) usize { - return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf)); + if (@hasDecl(@This(), "SYS_stat64")) { + return syscall2(SYS_stat64, @ptrToInt(pathname), @ptrToInt(statbuf)); + } else { + return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf)); + } } // TODO https://github.com/ziglang/zig/issues/265 pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize { - return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf)); + if (@hasDecl(@This(), "SYS_lstat64")) { + return syscall2(SYS_lstat64, @ptrToInt(pathname), @ptrToInt(statbuf)); + } else { + return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf)); + } } // TODO https://github.com/ziglang/zig/issues/265 pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize { - return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); + if (@hasDecl(@This(), "SYS_fstatat64")) { + return syscall4(SYS_fstatat64, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); + } else { + return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); + } } // TODO https://github.com/ziglang/zig/issues/265