commit ae39e7867db8053cd0538da10e144bf86bce4eba (tree)
parent b4e3424594aecbd5a038d7c3a9e1e01c66a239ee
Author: xEgoist <egoist@egoistic.dev>
Date: Fri, 7 Oct 2022 14:00:48 -0500
Added os check for std.fs.setAsCwd() to work with windows
Due to the unavailability of fchdir in Windows, a call for setting the
CWD needs to either call chdir with the path string or call
SetCurrentDirectory.
Either way, since we are dealing with a Handle in Windows, a call for
GetFinalPathNameByHandle is necessary for getting the file path first.
Diffstat:
1 file changed, 8 insertions(+), 0 deletions(-)
diff --git a/lib/std/fs.zig b/lib/std/fs.zig
@@ -1602,6 +1602,14 @@ pub const Dir = struct {
if (builtin.os.tag == .wasi) {
@compileError("changing cwd is not currently possible in WASI");
}
+ if (builtin.os.tag == .windows) {
+ var dir_path_buffer: [os.windows.PATH_MAX_WIDE]u16 = undefined;
+ var dir_path = try os.windows.GetFinalPathNameByHandle(self.fd, .{}, &dir_path_buffer);
+ if (builtin.link_libc) {
+ return os.chdirW(dir_path);
+ }
+ return os.windows.SetCurrentDirectory(dir_path);
+ }
try os.fchdir(self.fd);
}