| ... | ... | @@ -71,7 +71,16 @@ pub const PreopenList = struct { |
| 71 | 71 | |
| 72 | 72 | /// Populate the list with the preopens by issuing `std.os.wasi.fd_prestat_get` |
| 73 | 73 | /// and `std.os.wasi.fd_prestat_dir_name` syscalls to the runtime. |
| 74 | /// |
| 75 | /// If called more than once, it will clear its contents every time before |
| 76 | /// issuing the syscalls. |
| 74 | 77 | pub fn populate(self: *Self) Error!void { |
| 78 | // Clear contents if we're being called again |
| 79 | for (self.toOwnedSlice()) |preopen| { |
| 80 | switch (preopen.@"type") { |
| 81 | PreopenType.Dir => |path| self.buffer.allocator.free(path), |
| 82 | } |
| 83 | } |
| 75 | 84 | errdefer self.deinit(); |
| 76 | 85 | var fd: fd_t = 3; // start fd has to be beyond stdio fds |
| 77 | 86 | |
| ... | ... | @@ -123,6 +132,11 @@ pub const PreopenList = struct { |
| 123 | 132 | pub fn asSlice(self: *const Self) []const Preopen { |
| 124 | 133 | return self.buffer.items; |
| 125 | 134 | } |
| 135 | |
| 136 | /// The caller owns the returned memory. ArrayList becomes empty. |
| 137 | pub fn toOwnedSlice(self: *Self) []Preopen { |
| 138 | return self.buffer.toOwnedSlice(); |
| 139 | } |
| 126 | 140 | }; |
| 127 | 141 | |
| 128 | 142 | /// Convenience wrapper for `std.os.wasi.path_open` syscall. |