mirror of
https://github.com/ziglang/zig.git
synced 2026-02-05 22:16:58 +00:00
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.
This commit is contained in:
parent
b4e3424594
commit
ae39e7867d
@ -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);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user