authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2020-03-25 19:49:52-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-03-25 19:49:52-04:00
logdd66fbb96a2e1f85e7dacdce18ebc5f85d26d0cc
tree818e1c8d5606693e044e2a5c8f5764b77e819727
parente3fec6cce91a6ad5d63f78afe96649dc2aeea6a1
parentd554070de1a84882143e6ce7e3b14b9834ebf3d4
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #4811 from mikdusan/fix4634

self-hosted: use fs.selfExePathAlloc

2 files changed, 8 insertions(+), 11 deletions(-)

lib/std/fs.zig+7-10
......@@ -1509,6 +1509,13 @@ test "openSelfExe" {
15091509
15101510pub const SelfExePathError = os.ReadLinkError || os.SysCtlError;
15111511
1512/// `selfExePath` except allocates the result on the heap.
1513/// Caller owns returned memory.
1514pub fn selfExePathAlloc(allocator: *Allocator) ![]u8 {
1515 var buf: [MAX_PATH_BYTES]u8 = undefined;
1516 return mem.dupe(allocator, u8, try selfExePath(&buf));
1517}
1518
15121519/// Get the path to the current executable.
15131520/// If you only need the directory, use selfExeDirPath.
15141521/// If you only want an open file handle, use openSelfExe.
......@@ -1568,16 +1575,6 @@ pub fn selfExeDirPathAlloc(allocator: *Allocator) ![]u8 {
15681575/// Get the directory path that contains the current executable.
15691576/// Returned value is a slice of out_buffer.
15701577pub fn selfExeDirPath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]const u8 {
1571 if (builtin.os.tag == .linux) {
1572 // If the currently executing binary has been deleted,
1573 // the file path looks something like `/a/b/c/exe (deleted)`
1574 // This path cannot be opened, but it's valid for determining the directory
1575 // the executable was in when it was run.
1576 const full_exe_path = try os.readlinkC("/proc/self/exe", out_buffer);
1577 // Assume that /proc/self/exe has an absolute path, and therefore dirname
1578 // will not return null.
1579 return path.dirname(full_exe_path).?;
1580 }
15811578 const self_exe_path = try selfExePath(out_buffer);
15821579 // Assume that the OS APIs return absolute paths, and therefore dirname
15831580 // will not return null.
src-self-hosted/introspect.zig+1-1
......@@ -41,7 +41,7 @@ pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![
4141
4242/// Caller must free result
4343pub fn findZigLibDir(allocator: *mem.Allocator) ![]u8 {
44 const self_exe_path = try fs.selfExeDirPathAlloc(allocator);
44 const self_exe_path = try fs.selfExePathAlloc(allocator);
4545 defer allocator.free(self_exe_path);
4646
4747 var cur_path: []const u8 = self_exe_path;