# stdlib: Add emulated CWD to std.os for WASI targets · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/58f961f4cb9875bbce3070969438ecf08f392c9f)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 58f961f4cb9875bbce3070969438ecf08f392c9f

Requested commit: 58f961f4cb9875bbce3070969438ecf08f392c9f

Commit: 58f961f4cb9875bbce3070969438ecf08f392c9f

Tree: 0e4c4f98c023a9d3dd093dc63e519e26d9154930

Author: Cody Tapscott

Committer: Cody Tapscott

## Message

```
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.

```

## Parents

- [3605dd307ffff74726cc0ce5099599f1a6f9ddb2](https://git.cafe/gitcafe/zig/commit/3605dd307ffff74726cc0ce5099599f1a6f9ddb2?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/58f961f4cb9875bbce3070969438ecf08f392c9f?format=markdown)
