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.
This commit is contained in:
Robin Voetter 2019-08-29 10:34:05 +02:00
parent b3ac323a44
commit 108a51b110
4 changed files with 26 additions and 10 deletions

View File

@ -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,

View File

@ -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,
};
}

View File

@ -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,

View File

@ -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