# stdlib std.os: Improve wasi-libc parity for WASI CWD emulation · gitcafe/zig

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

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

Visibility: public

Requested revision: 7b090df6689909ba82ff46be4d21733f84f32c33

Requested commit: 7b090df6689909ba82ff46be4d21733f84f32c33

Commit: 7b090df6689909ba82ff46be4d21733f84f32c33

Tree: 105f0782e6ec8cd105402c689db814f8720c5858

Author: Cody Tapscott

Committer: Jakub Konka

## Message

```
stdlib std.os: Improve wasi-libc parity for WASI CWD emulation

Two major changes here:
  1. We store the CWD as a simple `[]const u8` and lookup Preopens for
     every absolute or CWD-referenced file operation, based on the
     Preopen with the longest match (i.e. most specific path)
  2. Preorders are normalized to POSIX absolute paths at init time.
     Behavior depends on the "cwd_root" parameter of `initPreopensWasi`:

	`cwd_root` is used for any Preopens that start with "."

	  For example:
            "./foo/bar" - inits to -> "{cwd_root}/foo/bar"
            "foo/bar"   - inits to -> "/foo/bar"
	    "/foo/bar"  - inits to -> "/foo/bar"

        `cwd_root` must be an absolute path.

	Using "/" as `cwd_root` gives behavior similar to wasi-libc.

```

## Parents

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

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