authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-29 18:47:58-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-29 18:47:58-08:00
logb1d1806fef56a72d0df14ad3a54c3074b1e55a69
tree8a66e8db31db8edd8f2aeb8f67d5300e8c650214
parent0a37ad2ec4daa04a845142508e0dd1326db7ee2d

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.

18 files changed, 41 insertions(+), 41 deletions(-)

lib/compiler/build_runner.zig+1-1
......@@ -83,7 +83,7 @@ pub fn main(init: process.Init.Minimal) !void {
8383 .io = io,
8484 .gpa = gpa,
8585 .manifest_dir = try local_cache_directory.handle.createDirPathOpen(io, "h", .{}),
86 .cwd = try process.currentDirAlloc(io, single_threaded_arena.allocator()),
86 .cwd = try process.currentPathAlloc(io, single_threaded_arena.allocator()),
8787 },
8888 .zig_exe = zig_exe,
8989 .environ_map = try init.environ.createMap(arena),
lib/std/Build/Cache.zig+4-4
......@@ -1315,7 +1315,7 @@ test "cache file and then recall it" {
13151315 var tmp = testing.tmpDir(.{});
13161316 defer tmp.cleanup();
13171317
1318 const cwd = try std.process.currentDirAlloc(io, testing.allocator);
1318 const cwd = try std.process.currentPathAlloc(io, testing.allocator);
13191319 defer testing.allocator.free(cwd);
13201320
13211321 const temp_file = "test.txt";
......@@ -1383,7 +1383,7 @@ test "check that changing a file makes cache fail" {
13831383 var tmp = testing.tmpDir(.{});
13841384 defer tmp.cleanup();
13851385
1386 const cwd = try std.process.currentDirAlloc(io, testing.allocator);
1386 const cwd = try std.process.currentPathAlloc(io, testing.allocator);
13871387 defer testing.allocator.free(cwd);
13881388
13891389 const temp_file = "cache_hash_change_file_test.txt";
......@@ -1459,7 +1459,7 @@ test "no file inputs" {
14591459 var tmp = testing.tmpDir(.{});
14601460 defer tmp.cleanup();
14611461
1462 const cwd = try std.process.currentDirAlloc(io, testing.allocator);
1462 const cwd = try std.process.currentPathAlloc(io, testing.allocator);
14631463 defer testing.allocator.free(cwd);
14641464
14651465 const temp_manifest_dir = "no_file_inputs_manifest_dir";
......@@ -1509,7 +1509,7 @@ test "Manifest with files added after initial hash work" {
15091509 var tmp = testing.tmpDir(.{});
15101510 defer tmp.cleanup();
15111511
1512 const cwd = try std.process.currentDirAlloc(io, testing.allocator);
1512 const cwd = try std.process.currentPathAlloc(io, testing.allocator);
15131513 defer testing.allocator.free(cwd);
15141514
15151515 const temp_file1 = "cache_hash_post_file_test1.txt";
lib/std/Build/Step/Options.zig+1-1
......@@ -519,7 +519,7 @@ test Options {
519519 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
520520 defer arena.deinit();
521521
522 const cwd = try std.process.currentDirAlloc(io, std.testing.allocator);
522 const cwd = try std.process.currentPathAlloc(io, std.testing.allocator);
523523 defer std.testing.allocator.free(cwd);
524524
525525 var graph: std.Build.Graph = .{
lib/std/Io.zig+1-1
......@@ -665,7 +665,7 @@ pub const VTable = struct {
665665 lockStderr: *const fn (?*anyopaque, ?Terminal.Mode) Cancelable!LockedStderr,
666666 tryLockStderr: *const fn (?*anyopaque, ?Terminal.Mode) Cancelable!?LockedStderr,
667667 unlockStderr: *const fn (?*anyopaque) void,
668 processCurrentDir: *const fn (?*anyopaque, buffer: []u8) std.process.CurrentDirError!usize,
668 processCurrentPath: *const fn (?*anyopaque, buffer: []u8) std.process.CurrentPathError!usize,
669669 processSetCurrentDir: *const fn (?*anyopaque, Dir) std.process.SetCurrentDirError!void,
670670 processReplace: *const fn (?*anyopaque, std.process.ReplaceOptions) std.process.ReplaceError,
671671 processReplacePath: *const fn (?*anyopaque, Dir, std.process.ReplaceOptions) std.process.ReplaceError,
lib/std/Io/Threaded.zig+4-4
......@@ -1643,7 +1643,7 @@ pub fn io(t: *Threaded) Io {
16431643 .lockStderr = lockStderr,
16441644 .tryLockStderr = tryLockStderr,
16451645 .unlockStderr = unlockStderr,
1646 .processCurrentDir = processCurrentDir,
1646 .processCurrentPath = processCurrentPath,
16471647 .processSetCurrentDir = processSetCurrentDir,
16481648 .processReplace = processReplace,
16491649 .processReplacePath = processReplacePath,
......@@ -1802,7 +1802,7 @@ pub fn ioBasic(t: *Threaded) Io {
18021802 .lockStderr = lockStderr,
18031803 .tryLockStderr = tryLockStderr,
18041804 .unlockStderr = unlockStderr,
1805 .processCurrentDir = processCurrentDir,
1805 .processCurrentPath = processCurrentPath,
18061806 .processSetCurrentDir = processSetCurrentDir,
18071807 .processReplace = processReplace,
18081808 .processReplacePath = processReplacePath,
......@@ -12606,7 +12606,7 @@ fn unlockStderr(userdata: ?*anyopaque) void {
1260612606 process.stderr_thread_mutex.unlock();
1260712607}
1260812608
12609fn processCurrentDir(userdata: ?*anyopaque, buffer: []u8) process.CurrentDirError!usize {
12609fn processCurrentPath(userdata: ?*anyopaque, buffer: []u8) process.CurrentPathError!usize {
1261012610 const t: *Threaded = @ptrCast(@alignCast(userdata));
1261112611 _ = t;
1261212612 if (is_windows) {
......@@ -12638,7 +12638,7 @@ fn processCurrentDir(userdata: ?*anyopaque, buffer: []u8) process.CurrentDirErro
1263812638 };
1263912639 switch (err) {
1264012640 .SUCCESS => return std.mem.findScalar(u8, buffer, 0).?,
12641 .NOENT => return error.CurrentWorkingDirectoryUnlinked,
12641 .NOENT => return error.CurrentDirUnlinked,
1264212642 .RANGE => return error.NameTooLong,
1264312643 .FAULT => |e| return errnoBug(e),
1264412644 .INVAL => |e| return errnoBug(e),
lib/std/fs/test.zig+1-1
......@@ -1787,7 +1787,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" {
17871787
17881788 const gpa = testing.allocator;
17891789
1790 const cwd = try std.process.currentDirAlloc(io, gpa);
1790 const cwd = try std.process.currentPathAlloc(io, gpa);
17911791 defer gpa.free(cwd);
17921792
17931793 const filename = try Dir.path.resolve(gpa, &.{ cwd, sub_path });
lib/std/process.zig+11-11
......@@ -63,22 +63,22 @@ pub const Init = struct {
6363 };
6464};
6565
66pub const CurrentDirError = error{
66pub const CurrentPathError = error{
6767 NameTooLong,
6868 /// Not possible on Windows. Always returned on WASI.
69 CurrentWorkingDirectoryUnlinked,
69 CurrentDirUnlinked,
7070} || Io.UnexpectedError;
7171
7272/// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/).
7373/// On other platforms, the result is an opaque sequence of bytes with no
7474/// particular encoding.
75pub fn currentDir(io: Io, buffer: []u8) CurrentDirError!usize {
76 return io.vtable.processCurrentDir(io.userdata, buffer);
75pub fn currentPath(io: Io, buffer: []u8) CurrentPathError!usize {
76 return io.vtable.processCurrentPath(io.userdata, buffer);
7777}
7878
79pub const CurrentDirAllocError = Allocator.Error || error{
79pub const CurrentPathAllocError = Allocator.Error || error{
8080 /// Not possible on Windows. Always returned on WASI.
81 CurrentWorkingDirectoryUnlinked,
81 CurrentDirUnlinked,
8282} || Io.UnexpectedError;
8383
8484/// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/).
......@@ -86,17 +86,17 @@ pub const CurrentDirAllocError = Allocator.Error || error{
8686/// particular encoding.
8787///
8888/// Caller owns returned memory.
89pub fn currentDirAlloc(io: Io, allocator: Allocator) CurrentDirAllocError![:0]u8 {
89pub fn currentPathAlloc(io: Io, allocator: Allocator) CurrentPathAllocError![:0]u8 {
9090 var buffer: [max_path_bytes]u8 = undefined;
91 const n = currentDir(io, &buffer) catch |err| switch (err) {
91 const n = currentPath(io, &buffer) catch |err| switch (err) {
9292 error.NameTooLong => unreachable,
9393 else => |e| return e,
9494 };
9595 return allocator.dupeZ(u8, buffer[0..n]);
9696}
9797
98test currentDirAlloc {
99 const cwd = try currentDirAlloc(testing.io, testing.allocator);
98test currentPathAlloc {
99 const cwd = try currentPathAlloc(testing.io, testing.allocator);
100100 testing.allocator.free(cwd);
101101}
102102
......@@ -453,7 +453,7 @@ pub fn spawnPath(io: Io, dir: Io.Dir, options: SpawnOptions) SpawnError!Child {
453453 return io.vtable.processSpawnPath(io.userdata, dir, options);
454454}
455455
456pub const RunError = CurrentDirError || posix.ReadError || SpawnError || posix.PollError || error{
456pub const RunError = CurrentPathError || posix.ReadError || SpawnError || posix.PollError || error{
457457 StdoutStreamTooLong,
458458 StderrStreamTooLong,
459459};
src/introspect.zig+4-4
......@@ -51,23 +51,23 @@ pub fn findZigLibDir(gpa: Allocator, io: Io) !Cache.Directory {
5151 return findZigLibDirFromSelfExe(gpa, io, cwd_path, self_exe_path);
5252}
5353
54/// Like `std.process.currentDirAlloc`, but also resolves the path with `Dir.path.resolve`. This
54/// Like `std.process.currentPathAlloc`, but also resolves the path with `Dir.path.resolve`. This
5555/// means the path has no repeated separators, no "." or ".." components, and no trailing separator.
5656/// On WASI, "" is returned instead of ".".
5757pub fn getResolvedCwd(io: Io, gpa: Allocator) error{
5858 OutOfMemory,
59 CurrentWorkingDirectoryUnlinked,
59 CurrentDirUnlinked,
6060 Unexpected,
6161}![]u8 {
6262 if (builtin.target.os.tag == .wasi) {
6363 if (std.debug.runtime_safety) {
64 const cwd = try std.process.currentDirAlloc(io, gpa);
64 const cwd = try std.process.currentPathAlloc(io, gpa);
6565 defer gpa.free(cwd);
6666 assert(mem.eql(u8, cwd, "."));
6767 }
6868 return "";
6969 }
70 const cwd = try std.process.currentDirAlloc(io, gpa);
70 const cwd = try std.process.currentPathAlloc(io, gpa);
7171 defer gpa.free(cwd);
7272 const resolved = try Dir.path.resolve(gpa, &.{cwd});
7373 assert(Dir.path.isAbsolute(resolved));
test/standalone/child_process/main.zig+1-1
......@@ -16,7 +16,7 @@ pub fn main(init: std.process.Init.Minimal) !void {
1616 defer threaded.deinit();
1717 const io = threaded.io();
1818
19 const process_cwd_path = try std.process.currentDirAlloc(io, gpa);
19 const process_cwd_path = try std.process.currentPathAlloc(io, gpa);
2020 defer gpa.free(process_cwd_path);
2121
2222 var environ_map = try init.environ.createMap(gpa);
test/standalone/posix/cwd.zig+5-5
......@@ -28,13 +28,13 @@ pub fn main(init: std.process.Init) !void {
2828// get current working directory and expect it to match given path
2929fn expect_cwd(io: Io, expected_cwd: []const u8) !void {
3030 var cwd_buf: [path_max]u8 = undefined;
31 const actual_cwd = cwd_buf[0..try std.process.currentDir(io, &cwd_buf)];
31 const actual_cwd = cwd_buf[0..try std.process.currentPath(io, &cwd_buf)];
3232 try std.testing.expectEqualStrings(actual_cwd, expected_cwd);
3333}
3434
3535fn test_chdir_self(io: Io) !void {
3636 var old_cwd_buf: [path_max]u8 = undefined;
37 const old_cwd = old_cwd_buf[0..try std.process.currentDir(io, &old_cwd_buf)];
37 const old_cwd = old_cwd_buf[0..try std.process.currentPath(io, &old_cwd_buf)];
3838
3939 // Try changing to the current directory
4040 try std.Io.Threaded.chdir(old_cwd);
......@@ -43,7 +43,7 @@ fn test_chdir_self(io: Io) !void {
4343
4444fn test_chdir_absolute(io: Io) !void {
4545 var old_cwd_buf: [path_max]u8 = undefined;
46 const old_cwd = old_cwd_buf[0..try std.process.currentDir(io, &old_cwd_buf)];
46 const old_cwd = old_cwd_buf[0..try std.process.currentPath(io, &old_cwd_buf)];
4747
4848 const parent = std.fs.path.dirname(old_cwd) orelse unreachable; // old_cwd should be absolute
4949
......@@ -62,7 +62,7 @@ fn test_chdir_relative(gpa: Allocator, io: Io, tmp_dir: Io.Dir) !void {
6262
6363 // Capture base working directory path, to build expected full path
6464 var base_cwd_buf: [path_max]u8 = undefined;
65 const base_cwd = base_cwd_buf[0..try std.process.currentDir(io, &base_cwd_buf)];
65 const base_cwd = base_cwd_buf[0..try std.process.currentPath(io, &base_cwd_buf)];
6666
6767 const expected_path = try std.fs.path.resolve(gpa, &.{ base_cwd, subdir_path });
6868 defer gpa.free(expected_path);
......@@ -71,7 +71,7 @@ fn test_chdir_relative(gpa: Allocator, io: Io, tmp_dir: Io.Dir) !void {
7171 try std.Io.Threaded.chdir(subdir_path);
7272
7373 var new_cwd_buf: [path_max]u8 = undefined;
74 const new_cwd = new_cwd_buf[0..try std.process.currentDir(io, &new_cwd_buf)];
74 const new_cwd = new_cwd_buf[0..try std.process.currentPath(io, &new_cwd_buf)];
7575
7676 // On Windows, fs.path.resolve returns an uppercase drive letter, but the drive letter returned by getcwd may be lowercase
7777 const resolved_cwd = try std.fs.path.resolve(gpa, &.{new_cwd});
test/standalone/self_exe_symlink/create-symlink.zig+1-1
......@@ -9,7 +9,7 @@ pub fn main(init: std.process.Init) !void {
99 const exe_path = it.next() orelse unreachable;
1010 const symlink_path = it.next() orelse unreachable;
1111
12 const cwd = try std.process.currentDirAlloc(io, init.arena.allocator());
12 const cwd = try std.process.currentPathAlloc(io, init.arena.allocator());
1313
1414 // If `exe_path` is relative to our cwd, we need to convert it to be relative to the dirname of `symlink_path`.
1515 const exe_rel_path = try std.fs.path.relative(gpa, cwd, init.environ_map, std.fs.path.dirname(symlink_path) orelse ".", exe_path);
test/standalone/windows_paths/relative.zig+1-1
......@@ -4,7 +4,7 @@ pub fn main(init: std.process.Init) !void {
44 const arena = init.arena.allocator();
55 const args = try init.minimal.args.toSlice(arena);
66 const io = init.io;
7 const cwd_path = try std.process.currentDirAlloc(io, arena);
7 const cwd_path = try std.process.currentPathAlloc(io, arena);
88
99 if (args.len < 3) return error.MissingArgs;
1010
test/standalone/windows_paths/test.zig+1-1
......@@ -10,7 +10,7 @@ pub fn main(init: std.process.Init) !void {
1010
1111 const exe_path = args[1];
1212
13 const cwd_path = try std.process.currentDirAlloc(io, arena);
13 const cwd_path = try std.process.currentPathAlloc(io, arena);
1414 const parsed_cwd_path = std.fs.path.parsePathWindows(u8, cwd_path);
1515
1616 if (parsed_cwd_path.kind == .drive_absolute and !std.ascii.isAlphabetic(cwd_path[0])) {
test/standalone/windows_spawn/main.zig+1-1
......@@ -8,7 +8,7 @@ const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral;
88pub fn main(init: std.process.Init) !void {
99 const gpa = init.gpa;
1010 const io = init.io;
11 const process_cwd_path = try std.process.currentDirAlloc(io, init.arena.allocator());
11 const process_cwd_path = try std.process.currentPathAlloc(io, init.arena.allocator());
1212 var initial_process_cwd = try Io.Dir.cwd().openDir(io, ".", .{});
1313 defer initial_process_cwd.close(io);
1414
tools/doctest.zig+1-1
......@@ -33,7 +33,7 @@ pub fn main(init: std.process.Init) !void {
3333 const arena = init.arena.allocator();
3434 const io = init.io;
3535 const environ_map = init.environ_map;
36 const cwd_path = try std.process.currentDirAlloc(io, arena);
36 const cwd_path = try std.process.currentPathAlloc(io, arena);
3737
3838 try environ_map.put("CLICOLOR_FORCE", "1");
3939
tools/incr-check.zig+1-1
......@@ -32,7 +32,7 @@ pub fn main(init: std.process.Init) !void {
3232 const arena = init.arena.allocator();
3333 const io = init.io;
3434 const environ_map = init.environ_map;
35 const cwd_path = try std.process.currentDirAlloc(io, arena);
35 const cwd_path = try std.process.currentPathAlloc(io, arena);
3636
3737 var opt_zig_exe: ?[]const u8 = null;
3838 var opt_input_file_name: ?[]const u8 = null;
tools/process_headers.zig+1-1
......@@ -145,7 +145,7 @@ pub fn main(init: std.process.Init) !void {
145145 const arena = init.arena.allocator();
146146 const io = init.io;
147147 const args = try init.minimal.args.toSlice(arena);
148 const cwd_path = try std.process.currentDirAlloc(io, arena);
148 const cwd_path = try std.process.currentPathAlloc(io, arena);
149149 const environ_map = init.environ_map;
150150
151151 var search_paths = std.array_list.Managed([]const u8).init(arena);
tools/update-linux-headers.zig+1-1
......@@ -146,7 +146,7 @@ pub fn main(init: std.process.Init) !void {
146146 const io = init.io;
147147 const args = try init.minimal.args.toSlice(arena);
148148 const environ_map = init.environ_map;
149 const cwd = try std.process.currentDirAlloc(io, arena);
149 const cwd = try std.process.currentPathAlloc(io, arena);
150150
151151 var search_paths = std.array_list.Managed([]const u8).init(arena);
152152 var opt_out_dir: ?[]const u8 = null;