summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-05-04 06:01:58 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-05-04 06:01:58 -0700
commit742a7bf9408b976c84ad947f9b39637f184482fa (patch)
tree142d7b615a58e35b70784f1af79ddfa917551be0
parentad23b416cbd93e49f6fdc0c096c2b309448ef1c2 (diff)
downloadtxr-742a7bf9408b976c84ad947f9b39637f184482fa.tar.gz
txr-742a7bf9408b976c84ad947f9b39637f184482fa.tar.bz2
txr-742a7bf9408b976c84ad947f9b39637f184482fa.zip
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.
-rw-r--r--txr.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/txr.c b/txr.c
index 5f2ea883..428a0ff0 100644
--- a/txr.c
+++ b/txr.c
@@ -40,6 +40,9 @@
#include <windows.h>
#undef TEXT
#endif
+#if __APPLE__
+#include <mach-o/dyld.h>
+#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)
{