authorgravatar for info@bnoordhuis.nlBen Noordhuis <info@bnoordhuis.nl> 2018-02-08 00:14:32+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-07 18:14:32-05:00
logdd20f558f0b3740a37c1d16a306e35f8cbe6a38f
treebc1eb4fbc5ac9406822ed747a8bbe10679635103
parentc88e6e8aeec1b9a7d6888f298fef7949770c288b

implement openSelfExe() on darwin (#753)


1 files changed, 11 insertions(+), 1 deletions(-)

std/os/index.zig+11-1
...@@ -1556,12 +1556,22 @@ pub fn openSelfExe() %io.File {...@@ -1556,12 +1556,22 @@ pub fn openSelfExe() %io.File {
1556 return io.File.openRead("/proc/self/exe", null);1556 return io.File.openRead("/proc/self/exe", null);
1557 },1557 },
1558 Os.macosx, Os.ios => {1558 Os.macosx, Os.ios => {
1559 @panic("TODO: openSelfExe on Darwin");1559 var fixed_buffer_mem: [darwin.PATH_MAX]u8 = undefined;
1560 var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
1561 const self_exe_path = try selfExePath(&fixed_allocator.allocator);
1562 return io.File.openRead(self_exe_path, null);
1560 },1563 },
1561 else => @compileError("Unsupported OS"),1564 else => @compileError("Unsupported OS"),
1562 }1565 }
1563}1566}
15641567
1568test "openSelfExe" {
1569 switch (builtin.os) {
1570 Os.linux, Os.macosx, Os.ios => (try openSelfExe()).close(),
1571 else => return, // Unsupported OS.
1572 }
1573}
1574
1565/// Get the path to the current executable.1575/// Get the path to the current executable.
1566/// If you only need the directory, use selfExeDirPath.1576/// If you only need the directory, use selfExeDirPath.
1567/// If you only want an open file handle, use openSelfExe.1577/// If you only want an open file handle, use openSelfExe.