| author | |
| committer | |
| log | fae4af9e1cf0383a74da808678d9369553bd878b |
| tree | ed7c56088028ad7795687ba6c3369ad323b1d4d4 |
| parent | 40812063cca77a84c58c8760ddf0ad9da3356962 |
3 files changed, 45 insertions(+), 7 deletions(-)
lib/std/fs/file.zig+2-2| ... | ... | @@ -30,6 +30,7 @@ pub const File = struct { |
| 30 | 30 | |
| 31 | 31 | pub const default_mode = switch (builtin.os.tag) { |
| 32 | 32 | .windows => 0, |
| 33 | .wasi => 0, | |
| 33 | 34 | else => 0o666, |
| 34 | 35 | }; |
| 35 | 36 | |
| ... | ... | @@ -267,11 +268,10 @@ pub const File = struct { |
| 267 | 268 | const atime = st.atime(); |
| 268 | 269 | const mtime = st.mtime(); |
| 269 | 270 | const ctime = st.ctime(); |
| 270 | const m = if (builtin.os.tag == .wasi) 0 else st.mode; | |
| 271 | 271 | return Stat{ |
| 272 | 272 | .inode = st.ino, |
| 273 | 273 | .size = @bitCast(u64, st.size), |
| 274 | .mode = m, | |
| 274 | .mode = st.mode, | |
| 275 | 275 | .atime = @as(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec, |
| 276 | 276 | .mtime = @as(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec, |
| 277 | 277 | .ctime = @as(i64, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec, |
lib/std/os.zig+2-2| ... | ... | @@ -2904,9 +2904,9 @@ pub const FStatError = error{ |
| 2904 | 2904 | |
| 2905 | 2905 | pub fn fstat(fd: fd_t) FStatError!Stat { |
| 2906 | 2906 | if (builtin.os.tag == .wasi) { |
| 2907 | var stat: Stat = undefined; | |
| 2907 | var stat: wasi.filestat_t = undefined; | |
| 2908 | 2908 | switch (wasi.fd_filestat_get(fd, &stat)) { |
| 2909 | wasi.ESUCCESS => return stat, | |
| 2909 | wasi.ESUCCESS => return Stat.fromFilestat(stat), | |
| 2910 | 2910 | wasi.EINVAL => unreachable, |
| 2911 | 2911 | wasi.EBADF => unreachable, // Always a race condition. |
| 2912 | 2912 | wasi.ENOMEM => return error.SystemResources, |
lib/std/os/bits/wasi.zig+41-3| ... | ... | @@ -3,11 +3,11 @@ pub const STDIN_FILENO = 0; |
| 3 | 3 | pub const STDOUT_FILENO = 1; |
| 4 | 4 | pub const STDERR_FILENO = 2; |
| 5 | 5 | |
| 6 | pub const mode_t = u32; | |
| 6 | pub const mode_t = u0; | |
| 7 | 7 | |
| 8 | 8 | pub const time_t = i64; // match https://github.com/CraneStation/wasi-libc |
| 9 | 9 | |
| 10 | pub const timespec = extern struct { | |
| 10 | pub const timespec = struct { | |
| 11 | 11 | tv_sec: time_t, |
| 12 | 12 | tv_nsec: isize, |
| 13 | 13 | |
| ... | ... | @@ -26,7 +26,45 @@ pub const timespec = extern struct { |
| 26 | 26 | } |
| 27 | 27 | }; |
| 28 | 28 | |
| 29 | pub const Stat = filestat_t; | |
| 29 | pub const Stat = struct { | |
| 30 | dev: device_t, | |
| 31 | ino: inode_t, | |
| 32 | mode: mode_t, | |
| 33 | filetype: filetype_t, | |
| 34 | nlink: linkcount_t, | |
| 35 | size: filesize_t, | |
| 36 | atim: timespec, | |
| 37 | mtim: timespec, | |
| 38 | ctim: timespec, | |
| 39 | ||
| 40 | const Self = @This(); | |
| 41 | ||
| 42 | pub fn fromFilestat(stat: filestat_t) Self { | |
| 43 | return Self{ | |
| 44 | .dev = stat.dev, | |
| 45 | .ino = stat.ino, | |
| 46 | .mode = 0, | |
| 47 | .filetype = stat.filetype, | |
| 48 | .nlink = stat.nlink, | |
| 49 | .size = stat.size, | |
| 50 | .atim = stat.atime(), | |
| 51 | .mtim = stat.mtime(), | |
| 52 | .ctim = stat.ctime(), | |
| 53 | }; | |
| 54 | } | |
| 55 | ||
| 56 | pub fn atime(self: Self) timespec { | |
| 57 | return self.atim; | |
| 58 | } | |
| 59 | ||
| 60 | pub fn mtime(self: Self) timespec { | |
| 61 | return self.mtim; | |
| 62 | } | |
| 63 | ||
| 64 | pub fn ctime(self: Self) timespec { | |
| 65 | return self.ctim; | |
| 66 | } | |
| 67 | }; | |
| 30 | 68 | |
| 31 | 69 | pub const AT_REMOVEDIR: u32 = 1; // there's no AT_REMOVEDIR in WASI, but we simulate here to match other OSes |
| 32 | 70 |