pub fn getResolvedCwd(io: Io, gpa: Allocator) std.process.CurrentPathAllocError![]u8 1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346pub fn getResolvedCwd(io: Io, gpa: Allocator) std.process.CurrentPathAllocError![]u8 {
if (builtin.os.tag == .wasi) {
if (std.debug.runtime_safety) {
const cwd = try std.process.currentPathAlloc(io, gpa);
defer gpa.free(cwd);
assert(mem.eql(u8, cwd, "."));
}
return "";
}
const cwd = try std.process.currentPathAlloc(io, gpa);
defer gpa.free(cwd);
const resolved = try Dir.path.resolve(gpa, &.{cwd});
assert(Dir.path.isAbsolute(resolved));
return resolved;
}
Like
std.process.currentPathAlloc, but also resolves the path withDir.path.resolve. This means the path has no repeated separators, no "." or ".." components, and no trailing separator. On WASI, "" is returned instead of ".".