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 {...@@ -30,6 +30,7 @@ pub const File = struct {
3030
31 pub const default_mode = switch (builtin.os.tag) {31 pub const default_mode = switch (builtin.os.tag) {
32 .windows => 0,32 .windows => 0,
33 .wasi => 0,
33 else => 0o666,34 else => 0o666,
34 };35 };
3536
...@@ -267,11 +268,10 @@ pub const File = struct {...@@ -267,11 +268,10 @@ pub const File = struct {
267 const atime = st.atime();268 const atime = st.atime();
268 const mtime = st.mtime();269 const mtime = st.mtime();
269 const ctime = st.ctime();270 const ctime = st.ctime();
270 const m = if (builtin.os.tag == .wasi) 0 else st.mode;
271 return Stat{271 return Stat{
272 .inode = st.ino,272 .inode = st.ino,
273 .size = @bitCast(u64, st.size),273 .size = @bitCast(u64, st.size),
274 .mode = m,274 .mode = st.mode,
275 .atime = @as(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,275 .atime = @as(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
276 .mtime = @as(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,276 .mtime = @as(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
277 .ctime = @as(i64, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,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,9 +2904,9 @@ pub const FStatError = error{
29042904
2905pub fn fstat(fd: fd_t) FStatError!Stat {2905pub fn fstat(fd: fd_t) FStatError!Stat {
2906 if (builtin.os.tag == .wasi) {2906 if (builtin.os.tag == .wasi) {
2907 var stat: Stat = undefined;2907 var stat: wasi.filestat_t = undefined;
2908 switch (wasi.fd_filestat_get(fd, &stat)) {2908 switch (wasi.fd_filestat_get(fd, &stat)) {
2909 wasi.ESUCCESS => return stat,2909 wasi.ESUCCESS => return Stat.fromFilestat(stat),
2910 wasi.EINVAL => unreachable,2910 wasi.EINVAL => unreachable,
2911 wasi.EBADF => unreachable, // Always a race condition.2911 wasi.EBADF => unreachable, // Always a race condition.
2912 wasi.ENOMEM => return error.SystemResources,2912 wasi.ENOMEM => return error.SystemResources,
lib/std/os/bits/wasi.zig+41-3
...@@ -3,11 +3,11 @@ pub const STDIN_FILENO = 0;...@@ -3,11 +3,11 @@ pub const STDIN_FILENO = 0;
3pub const STDOUT_FILENO = 1;3pub const STDOUT_FILENO = 1;
4pub const STDERR_FILENO = 2;4pub const STDERR_FILENO = 2;
55
6pub const mode_t = u32;6pub const mode_t = u0;
77
8pub const time_t = i64; // match https://github.com/CraneStation/wasi-libc8pub const time_t = i64; // match https://github.com/CraneStation/wasi-libc
99
10pub const timespec = extern struct {10pub const timespec = struct {
11 tv_sec: time_t,11 tv_sec: time_t,
12 tv_nsec: isize,12 tv_nsec: isize,
1313
...@@ -26,7 +26,45 @@ pub const timespec = extern struct {...@@ -26,7 +26,45 @@ pub const timespec = extern struct {
26 }26 }
27};27};
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
31pub const AT_REMOVEDIR: u32 = 1; // there's no AT_REMOVEDIR in WASI, but we simulate here to match other OSes69pub const AT_REMOVEDIR: u32 = 1; // there's no AT_REMOVEDIR in WASI, but we simulate here to match other OSes
3270