authorgravatar for egoist@egoistic.devxEgoist <egoist@egoistic.dev> 2022-10-07 14:00:48-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-15 11:05:15-04:00
logae39e7867db8053cd0538da10e144bf86bce4eba
tree9be029846cd6af428dc6d5dabec4b113ec70cc5b
parentb4e3424594aecbd5a038d7c3a9e1e01c66a239ee

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.

1 files changed, 8 insertions(+), 0 deletions(-)

lib/std/fs.zig+8
...@@ -1602,6 +1602,14 @@ pub const Dir = struct {...@@ -1602,6 +1602,14 @@ pub const Dir = struct {
1602 if (builtin.os.tag == .wasi) {1602 if (builtin.os.tag == .wasi) {
1603 @compileError("changing cwd is not currently possible in WASI");1603 @compileError("changing cwd is not currently possible in WASI");
1604 }1604 }
1605 if (builtin.os.tag == .windows) {
1606 var dir_path_buffer: [os.windows.PATH_MAX_WIDE]u16 = undefined;
1607 var dir_path = try os.windows.GetFinalPathNameByHandle(self.fd, .{}, &dir_path_buffer);
1608 if (builtin.link_libc) {
1609 return os.chdirW(dir_path);
1610 }
1611 return os.windows.SetCurrentDirectory(dir_path);
1612 }
1605 try os.fchdir(self.fd);1613 try os.fchdir(self.fd);
1606 }1614 }
16071615