| ... | @@ -10961,24 +10961,28 @@ pub fn main() !void { | ... | @@ -10961,24 +10961,28 @@ pub fn main() !void { |
| 10961 | {#code_begin|exe|preopens#} | 10961 | {#code_begin|exe|preopens#} |
| 10962 | {#target_wasi#} | 10962 | {#target_wasi#} |
| 10963 | const std = @import("std"); | 10963 | const std = @import("std"); |
| 10964 | const PreopenList = std.fs.wasi.PreopenList; | 10964 | const fs = std.fs; |
| 10965 | | 10965 | |
| 10966 | pub fn main() !void { | 10966 | pub fn main() !void { |
| 10967 | var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; | 10967 | var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; |
| 10968 | const gpa = general_purpose_allocator.allocator(); | 10968 | const gpa = general_purpose_allocator.allocator(); |
| 10969 | | 10969 | |
| 10970 | var preopens = PreopenList.init(gpa); | 10970 | var arena_instance = std.heap.ArenaAllocator.init(gpa); |
| 10971 | defer preopens.deinit(); | 10971 | defer arena_instance.deinit(); |
| | 10972 | const arena = arena_instance.allocator(); |
| 10972 | | 10973 | |
| 10973 | try preopens.populate(null); | 10974 | const preopens = try fs.wasi.preopensAlloc(arena); |
| 10974 | | 10975 | |
| 10975 | for (preopens.asSlice()) |preopen, i| { | 10976 | for (preopens.names) |preopen, i| { |
| 10976 | std.debug.print("{}: {}\n", .{ i, preopen }); | 10977 | std.debug.print("{}: {s}\n", .{ i, preopen }); |
| 10977 | } | 10978 | } |
| 10978 | } | 10979 | } |
| 10979 | {#code_end#} | 10980 | {#code_end#} |
| 10980 | {#shell_samp#}$ wasmtime --dir=. preopens.wasm | 10981 | {#shell_samp#}$ wasmtime --dir=. preopens.wasm |
| 10981 | 0: Preopen{ .fd = 3, .type = PreopenType{ .Dir = '.' } } | 10982 | 0: stdin |
| | 10983 | 1: stdout |
| | 10984 | 2: stderr |
| | 10985 | 3: . |
| 10982 | {#end_shell_samp#} | 10986 | {#end_shell_samp#} |
| 10983 | {#header_close#} | 10987 | {#header_close#} |
| 10984 | {#header_close#} | 10988 | {#header_close#} |