| author | |
| committer | |
| log | d4c33129cf86441a59079e15fd887711fae8d924 |
| tree | 339b93ebd6304d12bc5d6303ccfbd8a2e157f129 |
| parent | dd238352a4d3a9f02ff62d32cd109adabee30b66 |
This commit removes `std.os.openatWasi` function, and renames it to
`std.os.wasi.openat`. Additionally, the added `PreopenList.findByPath`
method allows querying the list for a matching preopen by path.3 files changed, 23 insertions(+), 12 deletions(-)
lib/std/fs.zig+2-2| ... | ... | @@ -602,7 +602,7 @@ pub const Dir = struct { |
| 602 | 602 | rights |= wasi.FD_WRITE | wasi.FD_DATASYNC | wasi.FD_SEEK | wasi.FD_FDSTAT_SET_FLAGS | wasi.FD_SYNC | wasi.FD_ALLOCATE | wasi.FD_ADVISE | wasi.FD_FILESTAT_SET_TIMES | wasi.FD_FILESTAT_SET_SIZE; |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | const fd = try os.openatWasi(self.fd, sub_path, 0x0, fdflags, rights); | |
| 605 | const fd = try wasi.openat(self.fd, sub_path, 0x0, fdflags, rights); | |
| 606 | 606 | |
| 607 | 607 | return File{ .handle = fd }; |
| 608 | 608 | } |
| ... | ... | @@ -713,7 +713,7 @@ pub const Dir = struct { |
| 713 | 713 | oflags |= wasi.O_EXCL; |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | const fd = try os.openatWasi(self.fd, sub_path, oflags, 0x0, rights); | |
| 716 | const fd = try wasi.openat(self.fd, sub_path, oflags, 0x0, rights); | |
| 717 | 717 | |
| 718 | 718 | return File{ .handle = fd }; |
| 719 | 719 | } |
lib/std/os.zig-10| ... | ... | @@ -923,16 +923,6 @@ pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: u32, mode: mode_t) Ope |
| 923 | 923 | return openatZ(dir_fd, &file_path_c, flags, mode); |
| 924 | 924 | } |
| 925 | 925 | |
| 926 | pub fn openatWasi(dir_fd: fd_t, file_path: []const u8, oflags: wasi.oflags_t, fdflags: wasi.fdflags_t, rights: wasi.rights_t) OpenError!fd_t { | |
| 927 | var fd: fd_t = undefined; | |
| 928 | switch (wasi.path_open(dir_fd, 0x0, file_path.ptr, file_path.len, oflags, rights, 0x0, fdflags, &fd)) { | |
| 929 | 0 => {}, | |
| 930 | // TODO map errors | |
| 931 | else => |err| return unexpectedErrno(err), | |
| 932 | } | |
| 933 | return fd; | |
| 934 | } | |
| 935 | ||
| 936 | 926 | pub const openatC = @compileError("deprecated: renamed to openatZ"); |
| 937 | 927 | |
| 938 | 928 | /// Open and possibly create a file. Keeps trying if it gets interrupted. |
lib/std/os/wasi.zig+21| ... | ... | @@ -94,11 +94,32 @@ pub const PreopenList = struct { |
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | pub fn find(self: *const Self, path: []const u8) ?*const Preopen { | |
| 98 | for (self.buffer.items) |preopen| { | |
| 99 | switch (preopen.@"type") { | |
| 100 | PreopenType.Dir => |preopen_path| { | |
| 101 | if (mem.eql(u8, path, preopen_path)) return &preopen; | |
| 102 | }, | |
| 103 | } | |
| 104 | } | |
| 105 | return null; | |
| 106 | } | |
| 107 | ||
| 97 | 108 | pub fn asSlice(self: *const Self) []const Preopen { |
| 98 | 109 | return self.buffer.items; |
| 99 | 110 | } |
| 100 | 111 | }; |
| 101 | 112 | |
| 113 | pub fn openat(dir_fd: fd_t, file_path: []const u8, oflags: oflags_t, fdflags: fdflags_t, rights: rights_t) std.os.OpenError!fd_t { | |
| 114 | var fd: fd_t = undefined; | |
| 115 | switch (path_open(dir_fd, 0x0, file_path.ptr, file_path.len, oflags, rights, 0x0, fdflags, &fd)) { | |
| 116 | 0 => {}, | |
| 117 | // TODO map errors | |
| 118 | else => |err| return std.os.unexpectedErrno(err), | |
| 119 | } | |
| 120 | return fd; | |
| 121 | } | |
| 122 | ||
| 102 | 123 | pub extern "wasi_snapshot_preview1" fn args_get(argv: [*][*:0]u8, argv_buf: [*]u8) errno_t; |
| 103 | 124 | pub extern "wasi_snapshot_preview1" fn args_sizes_get(argc: *usize, argv_buf_size: *usize) errno_t; |
| 104 | 125 |