zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit dd20f558f0b3740a37c1d16a306e35f8cbe6a38f (tree)
parent c88e6e8aeec1b9a7d6888f298fef7949770c288b
Author: Ben Noordhuis <info@bnoordhuis.nl>
Date:   Thu,  8 Feb 2018 00:14:32 +0100

implement openSelfExe() on darwin (#753)


Diffstat:
Mstd/os/index.zig | 12+++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/std/os/index.zig b/std/os/index.zig @@ -1556,12 +1556,22 @@ pub fn openSelfExe() %io.File { return io.File.openRead("/proc/self/exe", null); }, Os.macosx, Os.ios => { - @panic("TODO: openSelfExe on Darwin"); + var fixed_buffer_mem: [darwin.PATH_MAX]u8 = undefined; + var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]); + const self_exe_path = try selfExePath(&fixed_allocator.allocator); + return io.File.openRead(self_exe_path, null); }, else => @compileError("Unsupported OS"), } } +test "openSelfExe" { + switch (builtin.os) { + Os.linux, Os.macosx, Os.ios => (try openSelfExe()).close(), + else => return, // Unsupported OS. + } +} + /// Get the path to the current executable. /// If you only need the directory, use selfExeDirPath. /// If you only want an open file handle, use openSelfExe.