From dc2a21e83cdce6cc7071a491a9488b63c8bfa34c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 4 May 2018 06:01:58 -0700 Subject: Mac-OS: replace nonworking method of getting self-path. TXR's fall-back method of getting the executable's own path is broken in the Mac-OS port, which means that TXR doesn't work when invoked via PATH search. Mac-OS-specific code is required. * txr.c (get_self_path): New variant for Darwin, using the platform-specific function _NSGetExecutablePath. --- txr.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/txr.c b/txr.c index 5f2ea883..428a0ff0 100644 --- a/txr.c +++ b/txr.c @@ -40,6 +40,9 @@ #include #undef TEXT #endif +#if __APPLE__ +#include +#endif #include "lib.h" #include "stream.h" #include "gc.h" @@ -230,6 +233,16 @@ static val get_self_path(void) return string(self); } +#elif __APPLE__ +static val get_self_path(void) +{ + char self[PATH_MAX] = { 0 }; + uint32_t size = sizeof self; + + if (_NSGetExecutablePath(self, &size) != 0) + return nil; + return string_utf8(self); +} #else static val get_self_path(void) { -- cgit v1.2.3