authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2019-08-29 10:34:05+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2019-08-29 10:34:05+02:00
log108a51b11032ba3ed7864a653f87283853e6e318
tree7d15bb730c3688025eed7416e97e89b0d3b86910
parentb3ac323a448e1e8a816eab64777b855396afe6c8

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.

4 files changed, 26 insertions(+), 10 deletions(-)

std/debug.zig+1-1
......@@ -1053,7 +1053,7 @@ fn openSelfDebugInfoPosix(allocator: *mem.Allocator) !DwarfInfo {
10531053 S.self_exe_file = try fs.openSelfExe();
10541054 errdefer S.self_exe_file.close();
10551055
1056 const self_exe_mmap_len = mem.alignForward(try S.self_exe_file.getEndPos(), mem.page_size);
1056 const self_exe_mmap_len = mem.alignForward(@intCast(usize, try S.self_exe_file.getEndPos()), mem.page_size);
10571057 const self_exe_mmap = try os.mmap(
10581058 null,
10591059 self_exe_mmap_len,
std/fs/file.zig+3-3
......@@ -261,9 +261,9 @@ pub const File = struct {
261261 return Stat{
262262 .size = @bitCast(u64, st.size),
263263 .mode = st.mode,
264 .atime = atime.tv_sec * std.time.ns_per_s + atime.tv_nsec,
265 .mtime = mtime.tv_sec * std.time.ns_per_s + mtime.tv_nsec,
266 .ctime = ctime.tv_sec * std.time.ns_per_s + ctime.tv_nsec,
264 .atime = @intCast(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
265 .mtime = @intCast(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
266 .ctime = @intCast(i64, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
267267 };
268268 }
269269
std/os/bits/linux/arm-eabi.zig+2-2
......@@ -502,7 +502,7 @@ pub const msghdr_const = extern struct {
502502/// methods to accomplish this.
503503pub const Stat = extern struct {
504504 dev: u64,
505 __dev_patting: u32,
505 __dev_padding: u32,
506506 __ino_truncated: u32,
507507 mode: u32,
508508 nlink: u32,
......@@ -512,7 +512,7 @@ pub const Stat = extern struct {
512512 __rdev_padding: u32,
513513 size: i64,
514514 blksize: i32,
515 blocks: i64,
515 blocks: u64,
516516 atim: timespec,
517517 mtim: timespec,
518518 ctim: timespec,
std/os/linux.zig+20-4
......@@ -713,22 +713,38 @@ pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags:
713713}
714714
715715pub fn fstat(fd: i32, stat_buf: *Stat) usize {
716 return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
716 if (@hasDecl(@This(), "SYS_fstat64")) {
717 return syscall2(SYS_fstat64, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
718 } else {
719 return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
720 }
717721}
718722
719723// TODO https://github.com/ziglang/zig/issues/265
720724pub fn stat(pathname: [*]const u8, statbuf: *Stat) usize {
721 return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf));
725 if (@hasDecl(@This(), "SYS_stat64")) {
726 return syscall2(SYS_stat64, @ptrToInt(pathname), @ptrToInt(statbuf));
727 } else {
728 return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf));
729 }
722730}
723731
724732// TODO https://github.com/ziglang/zig/issues/265
725733pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize {
726 return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf));
734 if (@hasDecl(@This(), "SYS_lstat64")) {
735 return syscall2(SYS_lstat64, @ptrToInt(pathname), @ptrToInt(statbuf));
736 } else {
737 return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf));
738 }
727739}
728740
729741// TODO https://github.com/ziglang/zig/issues/265
730742pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize {
731 return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
743 if (@hasDecl(@This(), "SYS_fstatat64")) {
744 return syscall4(SYS_fstatat64, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
745 } else {
746 return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
747 }
732748}
733749
734750// TODO https://github.com/ziglang/zig/issues/265