Function setAsCwd [src]
Changes the current working directory to the open directory handle.
This modifies global state and can have surprising effects in multi-
threaded applications. Most applications and especially libraries should
not call this function as a general rule, however it can have use cases
in, for example, implementing a shell, or child process execution.
Not all targets support this. For example, WASI does not have the concept
of a current working directory.
Prototype
pub fn setAsCwd(self: Dir) !void
Parameters
self: Dir
Source
pub fn setAsCwd(self: Dir) !void {
if (native_os == .wasi) {
@compileError("changing cwd is not currently possible in WASI");
}
if (native_os == .windows) {
var dir_path_buffer: [windows.PATH_MAX_WIDE]u16 = undefined;
const dir_path = try windows.GetFinalPathNameByHandle(self.fd, .{}, &dir_path_buffer);
if (builtin.link_libc) {
return posix.chdirW(dir_path);
}
return windows.SetCurrentDirectory(dir_path);
}
try posix.fchdir(self.fd);
}