std.process: currentDir -> currentPath

In Zig standard library, Dir means an open directory handle. path
represents a file system identifier string. This function is better
named after "current path" than "current dir". "get" and "working" are
superfluous.
This commit is contained in:
Andrew Kelley 2026-01-29 18:47:58 -08:00
parent 0a37ad2ec4
commit b1d1806fef
18 changed files with 41 additions and 41 deletions

View file

@ -16,7 +16,7 @@ pub fn main(init: std.process.Init.Minimal) !void {
defer threaded.deinit();
const io = threaded.io();
const process_cwd_path = try std.process.currentDirAlloc(io, gpa);
const process_cwd_path = try std.process.currentPathAlloc(io, gpa);
defer gpa.free(process_cwd_path);
var environ_map = try init.environ.createMap(gpa);

View file

@ -28,13 +28,13 @@ pub fn main(init: std.process.Init) !void {
// get current working directory and expect it to match given path
fn expect_cwd(io: Io, expected_cwd: []const u8) !void {
var cwd_buf: [path_max]u8 = undefined;
const actual_cwd = cwd_buf[0..try std.process.currentDir(io, &cwd_buf)];
const actual_cwd = cwd_buf[0..try std.process.currentPath(io, &cwd_buf)];
try std.testing.expectEqualStrings(actual_cwd, expected_cwd);
}
fn test_chdir_self(io: Io) !void {
var old_cwd_buf: [path_max]u8 = undefined;
const old_cwd = old_cwd_buf[0..try std.process.currentDir(io, &old_cwd_buf)];
const old_cwd = old_cwd_buf[0..try std.process.currentPath(io, &old_cwd_buf)];
// Try changing to the current directory
try std.Io.Threaded.chdir(old_cwd);
@ -43,7 +43,7 @@ fn test_chdir_self(io: Io) !void {
fn test_chdir_absolute(io: Io) !void {
var old_cwd_buf: [path_max]u8 = undefined;
const old_cwd = old_cwd_buf[0..try std.process.currentDir(io, &old_cwd_buf)];
const old_cwd = old_cwd_buf[0..try std.process.currentPath(io, &old_cwd_buf)];
const parent = std.fs.path.dirname(old_cwd) orelse unreachable; // old_cwd should be absolute
@ -62,7 +62,7 @@ fn test_chdir_relative(gpa: Allocator, io: Io, tmp_dir: Io.Dir) !void {
// Capture base working directory path, to build expected full path
var base_cwd_buf: [path_max]u8 = undefined;
const base_cwd = base_cwd_buf[0..try std.process.currentDir(io, &base_cwd_buf)];
const base_cwd = base_cwd_buf[0..try std.process.currentPath(io, &base_cwd_buf)];
const expected_path = try std.fs.path.resolve(gpa, &.{ base_cwd, subdir_path });
defer gpa.free(expected_path);
@ -71,7 +71,7 @@ fn test_chdir_relative(gpa: Allocator, io: Io, tmp_dir: Io.Dir) !void {
try std.Io.Threaded.chdir(subdir_path);
var new_cwd_buf: [path_max]u8 = undefined;
const new_cwd = new_cwd_buf[0..try std.process.currentDir(io, &new_cwd_buf)];
const new_cwd = new_cwd_buf[0..try std.process.currentPath(io, &new_cwd_buf)];
// On Windows, fs.path.resolve returns an uppercase drive letter, but the drive letter returned by getcwd may be lowercase
const resolved_cwd = try std.fs.path.resolve(gpa, &.{new_cwd});

View file

@ -9,7 +9,7 @@ pub fn main(init: std.process.Init) !void {
const exe_path = it.next() orelse unreachable;
const symlink_path = it.next() orelse unreachable;
const cwd = try std.process.currentDirAlloc(io, init.arena.allocator());
const cwd = try std.process.currentPathAlloc(io, init.arena.allocator());
// If `exe_path` is relative to our cwd, we need to convert it to be relative to the dirname of `symlink_path`.
const exe_rel_path = try std.fs.path.relative(gpa, cwd, init.environ_map, std.fs.path.dirname(symlink_path) orelse ".", exe_path);

View file

@ -4,7 +4,7 @@ pub fn main(init: std.process.Init) !void {
const arena = init.arena.allocator();
const args = try init.minimal.args.toSlice(arena);
const io = init.io;
const cwd_path = try std.process.currentDirAlloc(io, arena);
const cwd_path = try std.process.currentPathAlloc(io, arena);
if (args.len < 3) return error.MissingArgs;

View file

@ -10,7 +10,7 @@ pub fn main(init: std.process.Init) !void {
const exe_path = args[1];
const cwd_path = try std.process.currentDirAlloc(io, arena);
const cwd_path = try std.process.currentPathAlloc(io, arena);
const parsed_cwd_path = std.fs.path.parsePathWindows(u8, cwd_path);
if (parsed_cwd_path.kind == .drive_absolute and !std.ascii.isAlphabetic(cwd_path[0])) {

View file

@ -8,7 +8,7 @@ const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral;
pub fn main(init: std.process.Init) !void {
const gpa = init.gpa;
const io = init.io;
const process_cwd_path = try std.process.currentDirAlloc(io, init.arena.allocator());
const process_cwd_path = try std.process.currentPathAlloc(io, init.arena.allocator());
var initial_process_cwd = try Io.Dir.cwd().openDir(io, ".", .{});
defer initial_process_cwd.close(io);