From 05bcc23f09653ece07f1874dcf5454322c3601a4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 12 Jan 2017 11:30:03 +0530 Subject: [PATCH] Make linux-launcher work on OS X as well --- linux-launcher.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/linux-launcher.c b/linux-launcher.c index ae969e745..1e9daf3c8 100644 --- a/linux-launcher.c +++ b/linux-launcher.c @@ -7,11 +7,16 @@ #include #include -#include #include #include #include #include +#ifdef __APPLE__ +#include +#include +#else +#include +#endif #define MIN(x, y) ((x) < (y)) ? (x) : (y) #define MAX_ARGC 1024 @@ -20,7 +25,14 @@ int main(int argc, char *argv[]) { char exe[PATH_MAX+1] = {0}; char lib[PATH_MAX+1] = {0}; char *final_argv[MAX_ARGC + 1] = {0}; +#ifdef __APPLE__ + uint32_t size = PATH_MAX; + char apple[PATH_MAX+1] = {0}; + if (_NSGetExecutablePath(apple, &size) != 0) { fprintf(stderr, "Failed to get path to executable\n"); return 1; } + if (realpath(apple, exe) == NULL) { fprintf(stderr, "realpath() failed on the executable's path\n"); return 1; } +#else if (realpath("/proc/self/exe", exe) == NULL) { fprintf(stderr, "Failed to read /proc/self/exe\n"); return 1; } +#endif char *exe_dir = dirname(exe); int num = snprintf(lib, PATH_MAX, "%s%s", exe_dir, "/../lib/kitty"); if (num < 0 || num >= PATH_MAX) { fprintf(stderr, "Failed to create path to /../lib/kitty\n"); return 1; }