| author | |
| committer | |
| log | 108a51b11032ba3ed7864a653f87283853e6e318 |
| tree | 7d15bb730c3688025eed7416e97e89b0d3b86910 |
| parent | b3ac323a448e1e8a816eab64777b855396afe6c8 |
- 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 { |
| 1053 | 1053 | S.self_exe_file = try fs.openSelfExe(); |
| 1054 | 1054 | errdefer S.self_exe_file.close(); |
| 1055 | 1055 | |
| 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); | |
| 1057 | 1057 | const self_exe_mmap = try os.mmap( |
| 1058 | 1058 | null, |
| 1059 | 1059 | self_exe_mmap_len, |
std/fs/file.zig+3-3| ... | ... | @@ -261,9 +261,9 @@ pub const File = struct { |
| 261 | 261 | return Stat{ |
| 262 | 262 | .size = @bitCast(u64, st.size), |
| 263 | 263 | .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, | |
| 267 | 267 | }; |
| 268 | 268 | } |
| 269 | 269 |
std/os/bits/linux/arm-eabi.zig+2-2| ... | ... | @@ -502,7 +502,7 @@ pub const msghdr_const = extern struct { |
| 502 | 502 | /// methods to accomplish this. |
| 503 | 503 | pub const Stat = extern struct { |
| 504 | 504 | dev: u64, |
| 505 | __dev_patting: u32, | |
| 505 | __dev_padding: u32, | |
| 506 | 506 | __ino_truncated: u32, |
| 507 | 507 | mode: u32, |
| 508 | 508 | nlink: u32, |
| ... | ... | @@ -512,7 +512,7 @@ pub const Stat = extern struct { |
| 512 | 512 | __rdev_padding: u32, |
| 513 | 513 | size: i64, |
| 514 | 514 | blksize: i32, |
| 515 | blocks: i64, | |
| 515 | blocks: u64, | |
| 516 | 516 | atim: timespec, |
| 517 | 517 | mtim: timespec, |
| 518 | 518 | 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: |
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | pub 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 | } | |
| 717 | 721 | } |
| 718 | 722 | |
| 719 | 723 | // TODO https://github.com/ziglang/zig/issues/265 |
| 720 | 724 | pub 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 | } | |
| 722 | 730 | } |
| 723 | 731 | |
| 724 | 732 | // TODO https://github.com/ziglang/zig/issues/265 |
| 725 | 733 | pub 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 | } | |
| 727 | 739 | } |
| 728 | 740 | |
| 729 | 741 | // TODO https://github.com/ziglang/zig/issues/265 |
| 730 | 742 | pub 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 | } | |
| 732 | 748 | } |
| 733 | 749 | |
| 734 | 750 | // TODO https://github.com/ziglang/zig/issues/265 |