| ... | ... | @@ -2193,17 +2193,21 @@ pub fn executablePath(io: Io, out_buffer: []u8) ExecutablePathError!usize { |
| 2193 | 2193 | /// |
| 2194 | 2194 | /// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/). |
| 2195 | 2195 | /// On other platforms, the result is an opaque sequence of bytes with no particular encoding. |
| 2196 | | pub fn executableDirPath(out_buffer: []u8) ExecutablePathError!usize { |
| 2197 | | const n = try executablePath(out_buffer); |
| 2196 | pub fn executableDirPath(io: Io, out_buffer: []u8) ExecutablePathError!usize { |
| 2197 | const n = try executablePath(io, out_buffer); |
| 2198 | 2198 | // Assert that the OS APIs return absolute paths, and therefore dirname |
| 2199 | 2199 | // 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; |
| 2201 | 2201 | } |
| 2202 | 2202 | |
| 2203 | 2203 | /// Same as `executableDirPath` except allocates the result. |
| 2204 | | pub fn executableDirPathAlloc(allocator: Allocator) ![]u8 { |
| 2204 | pub fn executableDirPathAlloc(io: Io, allocator: Allocator) ExecutablePathAllocError![]u8 { |
| 2205 | 2205 | 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]); |
| 2207 | 2211 | } |
| 2208 | 2212 | |
| 2209 | 2213 | pub const OpenExecutableError = File.OpenError || ExecutablePathError || File.LockError; |