diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-09-10 21:51:57 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-10 21:51:57 +0300 |
| commit | 425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch) | |
| tree | e52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/src/os/path.zig | |
| parent | 90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff) | |
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/src/os/path.zig')
| -rw-r--r-- | vendor/libghostty-vt/src/os/path.zig | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/vendor/libghostty-vt/src/os/path.zig b/vendor/libghostty-vt/src/os/path.zig index 730ae692..ba1a63f7 100644 --- a/vendor/libghostty-vt/src/os/path.zig +++ b/vendor/libghostty-vt/src/os/path.zig @@ -6,22 +6,19 @@ const testing = std.testing; /// Search for "cmd" in the PATH and return the absolute path. This will /// always allocate if there is a non-null result. The caller must free the /// resulting value. -pub fn expand(alloc: Allocator, cmd: []const u8) !?[]u8 { +pub fn expand( + io: std.Io, + alloc: Allocator, + environ_map: *const std.process.Environ.Map, + cmd: []const u8, +) !?[]u8 { // If the command already contains a slash, then we return it as-is // because it is assumed to be absolute or relative. if (std.mem.indexOfScalar(u8, cmd, '/') != null) { return try alloc.dupe(u8, cmd); } - const PATH = switch (builtin.os.tag) { - .windows => blk: { - const win_path = std.process.getenvW(std.unicode.utf8ToUtf16LeStringLiteral("PATH")) orelse return null; - const path = try std.unicode.utf16LeToUtf8Alloc(alloc, win_path); - break :blk path; - }, - else => std.posix.getenvZ("PATH") orelse return null, - }; - defer if (builtin.os.tag == .windows) alloc.free(PATH); + const PATH = environ_map.get("PATH") orelse return null; var path_buf: [std.fs.max_path_bytes]u8 = undefined; var it = std.mem.tokenizeScalar(u8, PATH, std.fs.path.delimiter); @@ -39,7 +36,8 @@ pub fn expand(alloc: Allocator, cmd: []const u8) !?[]u8 { const full_path = path_buf[0..path_len :0]; // Stat it - const f = std.fs.cwd().openFile( + const f = std.Io.Dir.cwd().openFile( + io, full_path, .{}, ) catch |err| switch (err) { @@ -52,9 +50,9 @@ pub fn expand(alloc: Allocator, cmd: []const u8) !?[]u8 { }, else => return err, }; - defer f.close(); - const stat = try f.stat(); - if (stat.kind != .directory and isExecutable(stat.mode)) { + defer f.close(io); + const stat = try f.stat(io); + if (stat.kind != .directory and isExecutable(stat.permissions)) { return try alloc.dupe(u8, full_path); } } @@ -64,26 +62,39 @@ pub fn expand(alloc: Allocator, cmd: []const u8) !?[]u8 { return null; } -fn isExecutable(mode: std.fs.File.Mode) bool { - if (builtin.os.tag == .windows) return true; - return mode & 0o0111 != 0; +fn isExecutable(perms: std.Io.File.Permissions) bool { + return switch (builtin.os.tag) { + .windows => true, + else => posix: { + break :posix switch (std.posix.mode_t) { + u0 => true, + else => perms.toMode() & 0o0111 != 0, + }; + }, + }; } // `uname -n` is the *nix equivalent of `hostname.exe` on Windows test "expand: hostname" { + var environ_map = try testing.environ.createMap(testing.allocator); + defer environ_map.deinit(); const executable = if (builtin.os.tag == .windows) "hostname.exe" else "uname"; - const path = (try expand(testing.allocator, executable)).?; + const path = (try expand(testing.io, testing.allocator, &environ_map, executable)).?; defer testing.allocator.free(path); try testing.expect(path.len > executable.len); } test "expand: does not exist" { - const path = try expand(testing.allocator, "thisreallyprobablydoesntexist123"); + var environ_map = try testing.environ.createMap(testing.allocator); + defer environ_map.deinit(); + const path = try expand(testing.io, testing.allocator, &environ_map, "thisreallyprobablydoesntexist123"); try testing.expect(path == null); } test "expand: slash" { - const path = (try expand(testing.allocator, "foo/env")).?; + var environ_map = try testing.environ.createMap(testing.allocator); + defer environ_map.deinit(); + const path = (try expand(testing.io, testing.allocator, &environ_map, "foo/env")).?; defer testing.allocator.free(path); try testing.expect(path.len == 7); } |
