authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-05-18 17:01:02+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-05-18 17:09:52+02:00
logfae4af9e1cf0383a74da808678d9369553bd878b
treeed7c56088028ad7795687ba6c3369ad323b1d4d4
parent40812063cca77a84c58c8760ddf0ad9da3356962

Make mode_t a 0-byte type in WASI


3 files changed, 45 insertions(+), 7 deletions(-)

lib/std/fs/file.zig+2-2
......@@ -30,6 +30,7 @@ pub const File = struct {
3030
3131 pub const default_mode = switch (builtin.os.tag) {
3232 .windows => 0,
33 .wasi => 0,
3334 else => 0o666,
3435 };
3536
......@@ -267,11 +268,10 @@ pub const File = struct {
267268 const atime = st.atime();
268269 const mtime = st.mtime();
269270 const ctime = st.ctime();
270 const m = if (builtin.os.tag == .wasi) 0 else st.mode;
271271 return Stat{
272272 .inode = st.ino,
273273 .size = @bitCast(u64, st.size),
274 .mode = m,
274 .mode = st.mode,
275275 .atime = @as(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
276276 .mtime = @as(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
277277 .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{
29042904
29052905pub fn fstat(fd: fd_t) FStatError!Stat {
29062906 if (builtin.os.tag == .wasi) {
2907 var stat: Stat = undefined;
2907 var stat: wasi.filestat_t = undefined;
29082908 switch (wasi.fd_filestat_get(fd, &stat)) {
2909 wasi.ESUCCESS => return stat,
2909 wasi.ESUCCESS => return Stat.fromFilestat(stat),
29102910 wasi.EINVAL => unreachable,
29112911 wasi.EBADF => unreachable, // Always a race condition.
29122912 wasi.ENOMEM => return error.SystemResources,
lib/std/os/bits/wasi.zig+41-3
......@@ -3,11 +3,11 @@ pub const STDIN_FILENO = 0;
33pub const STDOUT_FILENO = 1;
44pub const STDERR_FILENO = 2;
55
6pub const mode_t = u32;
6pub const mode_t = u0;
77
88pub const time_t = i64; // match https://github.com/CraneStation/wasi-libc
99
10pub const timespec = extern struct {
10pub const timespec = struct {
1111 tv_sec: time_t,
1212 tv_nsec: isize,
1313
......@@ -26,7 +26,45 @@ pub const timespec = extern struct {
2626 }
2727};
2828
29pub const Stat = filestat_t;
29pub 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};
3068
3169pub const AT_REMOVEDIR: u32 = 1; // there's no AT_REMOVEDIR in WASI, but we simulate here to match other OSes
3270