# windows: Make readLinkW APIs output WTF-16, reduce stack usage of callers · gitcafe/zig

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

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

Visibility: public

Requested revision: 6aa3570cb0e599e89748073612e8d0317100c807

Requested commit: 6aa3570cb0e599e89748073612e8d0317100c807

Commit: 6aa3570cb0e599e89748073612e8d0317100c807

Tree: f33c2d40c295b6e0a67c31a5b7b7d22f8cf49202

Author: Ryan Liptak

Committer: Ryan Liptak

## Message

```
windows: Make readLinkW APIs output WTF-16, reduce stack usage of callers

- Affects the following functions:
  + `std.fs.Dir.readLinkW`
  + `std.os.windows.ReadLink`
  + `std.os.windows.ntToWin32Namespace`
  + `std.posix.readlinkW`
  + `std.posix.readlinkatW`

Each of these functions (except `ntToWin32Namespace`) took WTF-16 as input and would output WTF-8, which makes optimal buffer re-use difficult at callsites and could force unnecessary WTF-16 <-> WTF-8 conversion during an intermediate step.

The functions have been updated to output WTF-16, and also allow for the path and the output to re-use the same buffer (i.e. in-place modification), which can reduce the stack usage at callsites. For example, all of `std.fs.Dir.readLink`/`readLinkZ`/`std.posix.readlink`/`readlinkZ`/`readlinkat`/`readlinkatZ` have had their stack usage reduced by one PathSpace struct (64 KiB) when targeting Windows.

The new `ntToWin32Namespace` takes an output buffer and returns a slice from that instead of returning a PathSpace, which is necessary to make the above possible.

```

## Parents

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

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