diff options
| author | Cody Tapscott <topolarity@tapscott.me> | 2022-03-01 10:17:05 -0700 |
|---|---|---|
| committer | Cody Tapscott <topolarity@tapscott.me> | 2022-03-03 14:31:49 -0700 |
| commit | 58f961f4cb9875bbce3070969438ecf08f392c9f (patch) | |
| tree | 0e4c4f98c023a9d3dd093dc63e519e26d9154930 /lib/std/testing.zig | |
| parent | 3605dd307ffff74726cc0ce5099599f1a6f9ddb2 (diff) | |
| download | zig-58f961f4cb9875bbce3070969438ecf08f392c9f.tar.gz zig-58f961f4cb9875bbce3070969438ecf08f392c9f.zip | |
stdlib: Add emulated CWD to std.os for WASI targets
This adds a special CWD file descriptor, AT.FDCWD (-2), to refer to the
current working directory. The `*at(...)` functions look for this and
resolve relative paths against the stored CWD. Absolute paths are
dynamically matched against the stored Preopens.
"os.initPreopensWasi()" must be called before std.os functions will
resolve relative or absolute paths correctly. This is asserted at
runtime.
Support has been added for: `open`, `rename`, `mkdir`, `rmdir`, `chdir`,
`fchdir`, `link`, `symlink`, `unlink`, `readlink`, `fstatat`, `access`,
and `faccessat`.
This also includes limited support for `getcwd()` and `realpath()`.
These return an error if the CWD does not correspond to a Preopen with
an absolute path. They also do not currently expand symlinks.
Diffstat (limited to 'lib/std/testing.zig')
| -rw-r--r-- | lib/std/testing.zig | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/std/testing.zig b/lib/std/testing.zig index 8d08792801..8e5a75feb7 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -327,8 +327,8 @@ fn getCwdOrWasiPreopen() std.fs.Dir { defer preopens.deinit(); preopens.populate() catch @panic("unable to make tmp dir for testing: unable to populate preopens"); - const preopen = preopens.find(std.fs.wasi.PreopenType{ .Dir = "." }) orelse - @panic("unable to make tmp dir for testing: didn't find '.' in the preopens"); + const preopen = preopens.find(std.fs.wasi.PreopenType{ .Dir = "/cwd" }) orelse + @panic("unable to make tmp dir for testing: didn't find '/cwd' in the preopens"); return std.fs.Dir{ .fd = preopen.fd }; } else { |
