| ... | @@ -2291,7 +2291,20 @@ pub fn selfExePathW(out_buffer: *[windows_util.PATH_MAX_WIDE]u16) ![]u16 { | ... | @@ -2291,7 +2291,20 @@ pub fn selfExePathW(out_buffer: *[windows_util.PATH_MAX_WIDE]u16) ![]u16 { |
| 2291 | pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | 2291 | pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { |
| 2292 | switch (builtin.os) { | 2292 | switch (builtin.os) { |
| 2293 | Os.linux => return readLink(out_buffer, "/proc/self/exe"), | 2293 | Os.linux => return readLink(out_buffer, "/proc/self/exe"), |
| 2294 | Os.freebsd => return readLink(out_buffer, "/proc/curproc/file"), | 2294 | Os.freebsd => { |
| | 2295 | var mib = [4]c_int{ posix.CTL_KERN, posix.KERN_PROC, posix.KERN_PROC_PATHNAME, -1}; |
| | 2296 | var out_len: usize = out_buffer.len; |
| | 2297 | const err = posix.getErrno(posix.sysctl(&mib, 4, out_buffer, &out_len, null, 0)); |
| | 2298 | |
| | 2299 | if (err == 0 ) return mem.toSlice(u8, out_buffer); |
| | 2300 | |
| | 2301 | return switch (err) { |
| | 2302 | posix.EFAULT => error.BadAdress, |
| | 2303 | posix.EPERM => error.PermissionDenied, |
| | 2304 | else => unexpectedErrorPosix(err), |
| | 2305 | }; |
| | 2306 | |
| | 2307 | }, |
| 2295 | Os.windows => { | 2308 | Os.windows => { |
| 2296 | var utf16le_buf: [windows_util.PATH_MAX_WIDE]u16 = undefined; | 2309 | var utf16le_buf: [windows_util.PATH_MAX_WIDE]u16 = undefined; |
| 2297 | const utf16le_slice = try selfExePathW(&utf16le_buf); | 2310 | const utf16le_slice = try selfExePathW(&utf16le_buf); |