| ... | @@ -2094,6 +2094,7 @@ test "openSelfExe" { | ... | @@ -2094,6 +2094,7 @@ test "openSelfExe" { |
| 2094 | /// | 2094 | /// |
| 2095 | /// On Linux, depends on procfs being mounted. If the currently executing binary has | 2095 | /// On Linux, depends on procfs being mounted. If the currently executing binary has |
| 2096 | /// been deleted, the file path looks something like `/a/b/c/exe (deleted)`. | 2096 | /// been deleted, the file path looks something like `/a/b/c/exe (deleted)`. |
| | 2097 | /// TODO make the return type of this a null terminated pointer |
| 2097 | pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | 2098 | pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { |
| 2098 | switch (builtin.os) { | 2099 | switch (builtin.os) { |
| 2099 | Os.linux => return readLink(out_buffer, "/proc/self/exe"), | 2100 | Os.linux => return readLink(out_buffer, "/proc/self/exe"), |
| ... | @@ -2117,7 +2118,7 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | ... | @@ -2117,7 +2118,7 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { |
| 2117 | var u32_len: u32 = @intCast(u32, out_buffer.len); // TODO shouldn't need this cast | 2118 | var u32_len: u32 = @intCast(u32, out_buffer.len); // TODO shouldn't need this cast |
| 2118 | const rc = c._NSGetExecutablePath(out_buffer, &u32_len); | 2119 | const rc = c._NSGetExecutablePath(out_buffer, &u32_len); |
| 2119 | if (rc != 0) return error.NameTooLong; | 2120 | if (rc != 0) return error.NameTooLong; |
| 2120 | return out_buffer[0..u32_len]; | 2121 | return mem.toSlice(u8, out_buffer); |
| 2121 | }, | 2122 | }, |
| 2122 | else => @compileError("Unsupported OS"), | 2123 | else => @compileError("Unsupported OS"), |
| 2123 | } | 2124 | } |