implement openSelfExe() on darwin (#753)

This commit is contained in:
Ben Noordhuis 2018-02-08 00:14:32 +01:00 committed by Andrew Kelley
parent c88e6e8aee
commit dd20f558f0

View File

@ -1556,12 +1556,22 @@ pub fn openSelfExe() %io.File {
return io.File.openRead("/proc/self/exe", null); return io.File.openRead("/proc/self/exe", null);
}, },
Os.macosx, Os.ios => { 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"), 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. /// Get the path to the current executable.
/// If you only need the directory, use selfExeDirPath. /// If you only need the directory, use selfExeDirPath.
/// If you only want an open file handle, use openSelfExe. /// If you only want an open file handle, use openSelfExe.