authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2020-03-25 18:40:28-04:00
committergravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2020-03-25 18:40:28-04:00
logd554070de1a84882143e6ce7e3b14b9834ebf3d4
tree0562f7a5ca9bc95ae4470c6d0269eeeb20ccee9e
parentf313ab18aecea1ade0b6a90d671352a641ad351a
signaturelock-open Commit is signed but in an unrecognized format.

self-hosted: use fs.selfExePathAlloc

- add fs.selfExePathAlloc - use fs.selfExePathAlloc instead of fs.selfExeDirPathAlloc - remove redundant code from fs.selfExeDirPath closes #4634

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;