Make linux-launcher work on OS X as well

This commit is contained in:
Kovid Goyal 2017-01-12 11:30:03 +05:30
parent dbda7c4fcb
commit 05bcc23f09

View File

@ -7,11 +7,16 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include <libgen.h> #include <libgen.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#ifdef __APPLE__
#include <mach-o/dyld.h>
#include <sys/syslimits.h>
#else
#include <limits.h>
#endif
#define MIN(x, y) ((x) < (y)) ? (x) : (y) #define MIN(x, y) ((x) < (y)) ? (x) : (y)
#define MAX_ARGC 1024 #define MAX_ARGC 1024
@ -20,7 +25,14 @@ int main(int argc, char *argv[]) {
char exe[PATH_MAX+1] = {0}; char exe[PATH_MAX+1] = {0};
char lib[PATH_MAX+1] = {0}; char lib[PATH_MAX+1] = {0};
char *final_argv[MAX_ARGC + 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; } if (realpath("/proc/self/exe", exe) == NULL) { fprintf(stderr, "Failed to read /proc/self/exe\n"); return 1; }
#endif
char *exe_dir = dirname(exe); char *exe_dir = dirname(exe);
int num = snprintf(lib, PATH_MAX, "%s%s", exe_dir, "/../lib/kitty"); 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; } if (num < 0 || num >= PATH_MAX) { fprintf(stderr, "Failed to create path to /../lib/kitty\n"); return 1; }