authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2025-12-19 03:11:15-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:10-08:00
log406950f7566f7f220847ab2faa2c26914dcda257
treec25d08b3d2111d961c9928ea6f0581e887fecc64
parent8767a9a6d1f6d92a1e9a98a31cb6dc98eb2c59f3

std.process: Fix executableDirPath functions


1 files changed, 9 insertions(+), 5 deletions(-)

lib/std/process.zig+9-5
......@@ -2193,17 +2193,21 @@ pub fn executablePath(io: Io, out_buffer: []u8) ExecutablePathError!usize {
21932193///
21942194/// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/).
21952195/// On other platforms, the result is an opaque sequence of bytes with no particular encoding.
2196pub fn executableDirPath(out_buffer: []u8) ExecutablePathError!usize {
2197 const n = try executablePath(out_buffer);
2196pub fn executableDirPath(io: Io, out_buffer: []u8) ExecutablePathError!usize {
2197 const n = try executablePath(io, out_buffer);
21982198 // Assert that the OS APIs return absolute paths, and therefore dirname
21992199 // will not return null.
2200 return std.fs.path.dirname(out_buffer[0..n]).?;
2200 return std.fs.path.dirname(out_buffer[0..n]).?.len;
22012201}
22022202
22032203/// Same as `executableDirPath` except allocates the result.
2204pub fn executableDirPathAlloc(allocator: Allocator) ![]u8 {
2204pub fn executableDirPathAlloc(io: Io, allocator: Allocator) ExecutablePathAllocError![]u8 {
22052205 var buffer: [max_path_bytes]u8 = undefined;
2206 return allocator.dupe(u8, try executableDirPath(&buffer));
2206 const dir_path_len = executableDirPath(io, &buffer) catch |err| switch (err) {
2207 error.NameTooLong => unreachable,
2208 else => |e| return e,
2209 };
2210 return allocator.dupe(u8, buffer[0..dir_path_len]);
22072211}
22082212
22092213pub const OpenExecutableError = File.OpenError || ExecutablePathError || File.LockError;