diff --git a/lib/compiler/build_runner.zig b/lib/compiler/build_runner.zig index 6ef8e71f7e..5ef74adaba 100644 --- a/lib/compiler/build_runner.zig +++ b/lib/compiler/build_runner.zig @@ -83,7 +83,7 @@ pub fn main(init: process.Init.Minimal) !void { .io = io, .gpa = gpa, .manifest_dir = try local_cache_directory.handle.createDirPathOpen(io, "h", .{}), - .cwd = try process.currentDirAlloc(io, single_threaded_arena.allocator()), + .cwd = try process.currentPathAlloc(io, single_threaded_arena.allocator()), }, .zig_exe = zig_exe, .environ_map = try init.environ.createMap(arena), diff --git a/lib/std/Build/Cache.zig b/lib/std/Build/Cache.zig index f595435749..0cf9dde531 100644 --- a/lib/std/Build/Cache.zig +++ b/lib/std/Build/Cache.zig @@ -1315,7 +1315,7 @@ test "cache file and then recall it" { var tmp = testing.tmpDir(.{}); defer tmp.cleanup(); - const cwd = try std.process.currentDirAlloc(io, testing.allocator); + const cwd = try std.process.currentPathAlloc(io, testing.allocator); defer testing.allocator.free(cwd); const temp_file = "test.txt"; @@ -1383,7 +1383,7 @@ test "check that changing a file makes cache fail" { var tmp = testing.tmpDir(.{}); defer tmp.cleanup(); - const cwd = try std.process.currentDirAlloc(io, testing.allocator); + const cwd = try std.process.currentPathAlloc(io, testing.allocator); defer testing.allocator.free(cwd); const temp_file = "cache_hash_change_file_test.txt"; @@ -1459,7 +1459,7 @@ test "no file inputs" { var tmp = testing.tmpDir(.{}); defer tmp.cleanup(); - const cwd = try std.process.currentDirAlloc(io, testing.allocator); + const cwd = try std.process.currentPathAlloc(io, testing.allocator); defer testing.allocator.free(cwd); const temp_manifest_dir = "no_file_inputs_manifest_dir"; @@ -1509,7 +1509,7 @@ test "Manifest with files added after initial hash work" { var tmp = testing.tmpDir(.{}); defer tmp.cleanup(); - const cwd = try std.process.currentDirAlloc(io, testing.allocator); + const cwd = try std.process.currentPathAlloc(io, testing.allocator); defer testing.allocator.free(cwd); const temp_file1 = "cache_hash_post_file_test1.txt"; diff --git a/lib/std/Build/Step/Options.zig b/lib/std/Build/Step/Options.zig index adef048423..34073264e8 100644 --- a/lib/std/Build/Step/Options.zig +++ b/lib/std/Build/Step/Options.zig @@ -519,7 +519,7 @@ test Options { var arena = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena.deinit(); - const cwd = try std.process.currentDirAlloc(io, std.testing.allocator); + const cwd = try std.process.currentPathAlloc(io, std.testing.allocator); defer std.testing.allocator.free(cwd); var graph: std.Build.Graph = .{ diff --git a/lib/std/Io.zig b/lib/std/Io.zig index 20c23e804e..72df9e34f3 100644 --- a/lib/std/Io.zig +++ b/lib/std/Io.zig @@ -665,7 +665,7 @@ pub const VTable = struct { lockStderr: *const fn (?*anyopaque, ?Terminal.Mode) Cancelable!LockedStderr, tryLockStderr: *const fn (?*anyopaque, ?Terminal.Mode) Cancelable!?LockedStderr, unlockStderr: *const fn (?*anyopaque) void, - processCurrentDir: *const fn (?*anyopaque, buffer: []u8) std.process.CurrentDirError!usize, + processCurrentPath: *const fn (?*anyopaque, buffer: []u8) std.process.CurrentPathError!usize, processSetCurrentDir: *const fn (?*anyopaque, Dir) std.process.SetCurrentDirError!void, processReplace: *const fn (?*anyopaque, std.process.ReplaceOptions) std.process.ReplaceError, processReplacePath: *const fn (?*anyopaque, Dir, std.process.ReplaceOptions) std.process.ReplaceError, diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index 1a01795213..87cf72190c 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -1643,7 +1643,7 @@ pub fn io(t: *Threaded) Io { .lockStderr = lockStderr, .tryLockStderr = tryLockStderr, .unlockStderr = unlockStderr, - .processCurrentDir = processCurrentDir, + .processCurrentPath = processCurrentPath, .processSetCurrentDir = processSetCurrentDir, .processReplace = processReplace, .processReplacePath = processReplacePath, @@ -1802,7 +1802,7 @@ pub fn ioBasic(t: *Threaded) Io { .lockStderr = lockStderr, .tryLockStderr = tryLockStderr, .unlockStderr = unlockStderr, - .processCurrentDir = processCurrentDir, + .processCurrentPath = processCurrentPath, .processSetCurrentDir = processSetCurrentDir, .processReplace = processReplace, .processReplacePath = processReplacePath, @@ -12606,7 +12606,7 @@ fn unlockStderr(userdata: ?*anyopaque) void { process.stderr_thread_mutex.unlock(); } -fn processCurrentDir(userdata: ?*anyopaque, buffer: []u8) process.CurrentDirError!usize { +fn processCurrentPath(userdata: ?*anyopaque, buffer: []u8) process.CurrentPathError!usize { const t: *Threaded = @ptrCast(@alignCast(userdata)); _ = t; if (is_windows) { @@ -12638,7 +12638,7 @@ fn processCurrentDir(userdata: ?*anyopaque, buffer: []u8) process.CurrentDirErro }; switch (err) { .SUCCESS => return std.mem.findScalar(u8, buffer, 0).?, - .NOENT => return error.CurrentWorkingDirectoryUnlinked, + .NOENT => return error.CurrentDirUnlinked, .RANGE => return error.NameTooLong, .FAULT => |e| return errnoBug(e), .INVAL => |e| return errnoBug(e), diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index be59393e3d..d0ec6b33e9 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -1787,7 +1787,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" { const gpa = testing.allocator; - const cwd = try std.process.currentDirAlloc(io, gpa); + const cwd = try std.process.currentPathAlloc(io, gpa); defer gpa.free(cwd); const filename = try Dir.path.resolve(gpa, &.{ cwd, sub_path }); diff --git a/lib/std/process.zig b/lib/std/process.zig index dd3e07c1ea..5bcacddc84 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -63,22 +63,22 @@ pub const Init = struct { }; }; -pub const CurrentDirError = error{ +pub const CurrentPathError = error{ NameTooLong, /// Not possible on Windows. Always returned on WASI. - CurrentWorkingDirectoryUnlinked, + CurrentDirUnlinked, } || Io.UnexpectedError; /// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/). /// On other platforms, the result is an opaque sequence of bytes with no /// particular encoding. -pub fn currentDir(io: Io, buffer: []u8) CurrentDirError!usize { - return io.vtable.processCurrentDir(io.userdata, buffer); +pub fn currentPath(io: Io, buffer: []u8) CurrentPathError!usize { + return io.vtable.processCurrentPath(io.userdata, buffer); } -pub const CurrentDirAllocError = Allocator.Error || error{ +pub const CurrentPathAllocError = Allocator.Error || error{ /// Not possible on Windows. Always returned on WASI. - CurrentWorkingDirectoryUnlinked, + CurrentDirUnlinked, } || Io.UnexpectedError; /// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/). @@ -86,17 +86,17 @@ pub const CurrentDirAllocError = Allocator.Error || error{ /// particular encoding. /// /// Caller owns returned memory. -pub fn currentDirAlloc(io: Io, allocator: Allocator) CurrentDirAllocError![:0]u8 { +pub fn currentPathAlloc(io: Io, allocator: Allocator) CurrentPathAllocError![:0]u8 { var buffer: [max_path_bytes]u8 = undefined; - const n = currentDir(io, &buffer) catch |err| switch (err) { + const n = currentPath(io, &buffer) catch |err| switch (err) { error.NameTooLong => unreachable, else => |e| return e, }; return allocator.dupeZ(u8, buffer[0..n]); } -test currentDirAlloc { - const cwd = try currentDirAlloc(testing.io, testing.allocator); +test currentPathAlloc { + const cwd = try currentPathAlloc(testing.io, testing.allocator); testing.allocator.free(cwd); } @@ -453,7 +453,7 @@ pub fn spawnPath(io: Io, dir: Io.Dir, options: SpawnOptions) SpawnError!Child { return io.vtable.processSpawnPath(io.userdata, dir, options); } -pub const RunError = CurrentDirError || posix.ReadError || SpawnError || posix.PollError || error{ +pub const RunError = CurrentPathError || posix.ReadError || SpawnError || posix.PollError || error{ StdoutStreamTooLong, StderrStreamTooLong, }; diff --git a/src/introspect.zig b/src/introspect.zig index 36e94e979f..0cba9fdcc4 100644 --- a/src/introspect.zig +++ b/src/introspect.zig @@ -51,23 +51,23 @@ pub fn findZigLibDir(gpa: Allocator, io: Io) !Cache.Directory { return findZigLibDirFromSelfExe(gpa, io, cwd_path, self_exe_path); } -/// Like `std.process.currentDirAlloc`, but also resolves the path with `Dir.path.resolve`. This +/// Like `std.process.currentPathAlloc`, but also resolves the path with `Dir.path.resolve`. This /// means the path has no repeated separators, no "." or ".." components, and no trailing separator. /// On WASI, "" is returned instead of ".". pub fn getResolvedCwd(io: Io, gpa: Allocator) error{ OutOfMemory, - CurrentWorkingDirectoryUnlinked, + CurrentDirUnlinked, Unexpected, }![]u8 { if (builtin.target.os.tag == .wasi) { if (std.debug.runtime_safety) { - const cwd = try std.process.currentDirAlloc(io, gpa); + const cwd = try std.process.currentPathAlloc(io, gpa); defer gpa.free(cwd); assert(mem.eql(u8, cwd, ".")); } return ""; } - const cwd = try std.process.currentDirAlloc(io, gpa); + 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)); diff --git a/test/standalone/child_process/main.zig b/test/standalone/child_process/main.zig index 159be62a9d..d252ee414d 100644 --- a/test/standalone/child_process/main.zig +++ b/test/standalone/child_process/main.zig @@ -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); diff --git a/test/standalone/posix/cwd.zig b/test/standalone/posix/cwd.zig index e5e376784a..2588bde34f 100644 --- a/test/standalone/posix/cwd.zig +++ b/test/standalone/posix/cwd.zig @@ -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}); diff --git a/test/standalone/self_exe_symlink/create-symlink.zig b/test/standalone/self_exe_symlink/create-symlink.zig index aaa015c4b0..36a0c09080 100644 --- a/test/standalone/self_exe_symlink/create-symlink.zig +++ b/test/standalone/self_exe_symlink/create-symlink.zig @@ -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); diff --git a/test/standalone/windows_paths/relative.zig b/test/standalone/windows_paths/relative.zig index 7dcde62d50..6fd2fc188a 100644 --- a/test/standalone/windows_paths/relative.zig +++ b/test/standalone/windows_paths/relative.zig @@ -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; diff --git a/test/standalone/windows_paths/test.zig b/test/standalone/windows_paths/test.zig index 47b13415a8..1170de47ac 100644 --- a/test/standalone/windows_paths/test.zig +++ b/test/standalone/windows_paths/test.zig @@ -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])) { diff --git a/test/standalone/windows_spawn/main.zig b/test/standalone/windows_spawn/main.zig index 0bb8e7fe16..4b37e3cf6e 100644 --- a/test/standalone/windows_spawn/main.zig +++ b/test/standalone/windows_spawn/main.zig @@ -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); diff --git a/tools/doctest.zig b/tools/doctest.zig index 5afec8e62c..55b8ca7bfb 100644 --- a/tools/doctest.zig +++ b/tools/doctest.zig @@ -33,7 +33,7 @@ pub fn main(init: std.process.Init) !void { const arena = init.arena.allocator(); const io = init.io; const environ_map = init.environ_map; - const cwd_path = try std.process.currentDirAlloc(io, arena); + const cwd_path = try std.process.currentPathAlloc(io, arena); try environ_map.put("CLICOLOR_FORCE", "1"); diff --git a/tools/incr-check.zig b/tools/incr-check.zig index e15a91b548..c9564f85c2 100644 --- a/tools/incr-check.zig +++ b/tools/incr-check.zig @@ -32,7 +32,7 @@ pub fn main(init: std.process.Init) !void { const arena = init.arena.allocator(); const io = init.io; const environ_map = init.environ_map; - const cwd_path = try std.process.currentDirAlloc(io, arena); + const cwd_path = try std.process.currentPathAlloc(io, arena); var opt_zig_exe: ?[]const u8 = null; var opt_input_file_name: ?[]const u8 = null; diff --git a/tools/process_headers.zig b/tools/process_headers.zig index 6e5ab38797..3be919b303 100644 --- a/tools/process_headers.zig +++ b/tools/process_headers.zig @@ -145,7 +145,7 @@ pub fn main(init: std.process.Init) !void { const arena = init.arena.allocator(); const io = init.io; const args = try init.minimal.args.toSlice(arena); - const cwd_path = try std.process.currentDirAlloc(io, arena); + const cwd_path = try std.process.currentPathAlloc(io, arena); const environ_map = init.environ_map; var search_paths = std.array_list.Managed([]const u8).init(arena); diff --git a/tools/update-linux-headers.zig b/tools/update-linux-headers.zig index 649459a634..c5f556f53c 100644 --- a/tools/update-linux-headers.zig +++ b/tools/update-linux-headers.zig @@ -146,7 +146,7 @@ pub fn main(init: std.process.Init) !void { const io = init.io; const args = try init.minimal.args.toSlice(arena); const environ_map = init.environ_map; - const cwd = try std.process.currentDirAlloc(io, arena); + const cwd = try std.process.currentPathAlloc(io, arena); var search_paths = std.array_list.Managed([]const u8).init(arena); var opt_out_dir: ?[]const u8 = null;