summaryrefslogtreecommitdiff
path: root/perl.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2011-09-21 15:33:09 +0100
committerNicholas Clark <nick@ccl4.org>2011-09-27 22:25:05 +0200
commitae60cb464cebf89579ec0ff91db8b792b2f1e7cd (patch)
treefc1ab2f4a1d4d5360ffaf2df304bfe7c03f8c76c /perl.c
parent2982a345b7a1edb63720282eef0fba5c61d0e6b5 (diff)
downloadperl-ae60cb464cebf89579ec0ff91db8b792b2f1e7cd.tar.gz
Where available, use _NSGetExecutablePath() to make $^X absolute.
In Configure, check whether _NSGetExecutablePath() can be used to find the absolute pathname of the executable. If so, set usensgetexecutablepath in config.sh and USE_NSGETEXECUTABLEPATH in config.h. If this is set, then use this approach in S_set_caret_X() to canonicalise $^X as an absolute path. This approach works on OS X, and possible on other platforms that use dyld.
Diffstat (limited to 'perl.c')
-rw-r--r--perl.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/perl.c b/perl.c
index 5d2159d089..4285834173 100644
--- a/perl.c
+++ b/perl.c
@@ -42,6 +42,10 @@
# include <sys/sysctl.h>
#endif
+#ifdef USE_NSGETEXECUTABLEPATH
+# include <mach-o/dyld.h>
+#endif
+
#ifdef DEBUG_LEAKING_SCALARS_FORK_DUMP
# ifdef I_SYSUIO
# include <sys/uio.h>
@@ -1414,6 +1418,26 @@ S_set_caret_X(pTHX) {
return;
}
}
+# elif defined(USE_NSGETEXECUTABLEPATH)
+ char buf[1];
+ uint32_t size = sizeof(buf);
+ int result;
+
+ _NSGetExecutablePath(buf, &size);
+ if (size < MAXPATHLEN * MAXPATHLEN) {
+ sv_grow(caret_x, size);
+ if (_NSGetExecutablePath(SvPVX(caret_x), &size) == 0) {
+ char *const tidied = realpath(SvPVX(caret_x), NULL);
+ if (tidied) {
+ sv_setpv(caret_x, tidied);
+ free(tidied);
+ } else {
+ SvPOK_only(caret_x);
+ SvCUR_set(caret_x, size);
+ }
+ return;
+ }
+ }
# elif defined(HAS_PROCSELFEXE)
char buf[MAXPATHLEN];
int len = readlink(PROCSELFEXE_PATH, buf, sizeof(buf) - 1);