summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xConfigure102
-rw-r--r--Cross/config.sh-arm-linux1
-rw-r--r--NetWare/config.wc1
-rw-r--r--Porting/Glossary5
-rw-r--r--Porting/config.sh1
-rwxr-xr-xconfig_h.SH7
-rw-r--r--configure.com1
-rw-r--r--epoc/config.sh1
-rw-r--r--perl.c24
-rw-r--r--plan9/config_sh.sample1
-rw-r--r--symbian/config.sh1
-rw-r--r--t/op/magic.t3
-rw-r--r--uconfig.h11
-rw-r--r--uconfig.sh1
-rw-r--r--uconfig64.sh1
-rw-r--r--win32/config.ce1
-rw-r--r--win32/config.gc1
-rw-r--r--win32/config.gc641
-rw-r--r--win32/config.gc64nox1
-rw-r--r--win32/config.vc1
-rw-r--r--win32/config.vc641
21 files changed, 164 insertions, 3 deletions
diff --git a/Configure b/Configure
index 691bd81964..1f0dbefee4 100755
--- a/Configure
+++ b/Configure
@@ -1229,6 +1229,7 @@ nm_opt=''
nm_so_opt=''
runnm=''
usenm=''
+usensgetexecutablepath=''
useperlio=''
usesocks=''
d_oldpthreads=''
@@ -19462,6 +19463,106 @@ $rm_try
set usekernprocpathname
eval $setvar
+: Determine if we can use _NSGetExecutablePath to find executing program
+echo " "
+echo "Determining whether we can use _NSGetExecutablePath to find executing program..." >&4
+$cat >try.c <<'EOM'
+/* Intentionally a long probe as I'd like to sanity check that the exact
+ approach is going to work, as thinking it will work, but only having it
+ part working at runtime is worse than not having it. */
+#include <mach-o/dyld.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/param.h>
+#include <string.h>
+
+int
+main(int argc, char **argv) {
+ char buf[1];
+ uint32_t size = sizeof(buf);
+ int result;
+ char *buffer;
+ char *tidied;
+ char *argv_leaf = strrchr(argv[0], '/');
+ char *tidied_leaf;
+
+ if (!argv_leaf) {
+ fprintf(stderr, "Can't locate / in '%s'\n", argv[0]);
+ return 1;
+ }
+
+ _NSGetExecutablePath(buf, &size);
+ if (size > MAXPATHLEN * MAXPATHLEN) {
+ fprintf(stderr, "_NSGetExecutablePath size %u is too long for a path\n",
+ (unsigned int) size);
+ return 2;
+ }
+
+ buffer = malloc(size);
+ if (!buffer) {
+ perror("malloc");
+ return 3;
+ }
+
+ result = _NSGetExecutablePath(buffer, &size);
+ if (result != 0) {
+ fprintf(stderr, "_NSGetExecutablePath returned %i for a size of %u\n",
+ result, (unsigned int) size);
+ return 4;
+ }
+
+ tidied = realpath(buffer, NULL);
+ if (!tidied) {
+ perror("realpath");
+ return 5;
+ }
+
+ free(buffer);
+
+ if (*tidied != '/') {
+ fprintf(stderr, "Not an absolute path: '%s'\n", tidied);
+ return 6;
+ }
+
+ if (strstr(tidied, "/./")) {
+ fprintf(stderr, "Contains /./: '%s'\n", tidied);
+ return 7;
+ }
+
+ if (strstr(tidied, "/../")) {
+ fprintf(stderr, "Contains /../: '%s'\n", tidied);
+ return 8;
+ }
+
+ tidied_leaf = strrchr(tidied, '/');
+ if (strcmp(tidied_leaf, argv_leaf) != 0) {
+ fprintf(stderr, "Leafnames differ: '%s' vs '%s'\n", argv[0], tidied);
+ return 9;
+ }
+
+ free(tidied);
+
+ return 0;
+}
+EOM
+
+val=$undef
+set try
+if eval $compile_ok; then
+ if $run ./try; then
+ echo "You can use _NSGetExecutablePath to find the executing program." >&4
+ val="$define"
+ else
+ echo "Nope, _NSGetExecutablePath doesn't work here." >&4
+ fi
+else
+ echo "I'm unable to compile the test program." >&4
+ echo "I'll assume no _NSGetExecutablePath here." >&4
+fi
+$rm_try
+set usensgetexecutablepath
+eval $setvar
+
: Check how to flush
echo " "
$cat >&4 <<EOM
@@ -23558,6 +23659,7 @@ usemorebits='$usemorebits'
usemultiplicity='$usemultiplicity'
usemymalloc='$usemymalloc'
usenm='$usenm'
+usensgetexecutablepath='$usensgetexecutablepath'
useopcode='$useopcode'
useperlio='$useperlio'
useposix='$useposix'
diff --git a/Cross/config.sh-arm-linux b/Cross/config.sh-arm-linux
index 78e8829d59..e611e353f4 100644
--- a/Cross/config.sh-arm-linux
+++ b/Cross/config.sh-arm-linux
@@ -1032,6 +1032,7 @@ usemorebits='undef'
usemultiplicity='undef'
usemymalloc='n'
usenm='false'
+usensgetexecutablepath='undef'
useopcode='true'
useperlio='define'
useposix='true'
diff --git a/NetWare/config.wc b/NetWare/config.wc
index 72118f439c..6750b8c3c7 100644
--- a/NetWare/config.wc
+++ b/NetWare/config.wc
@@ -995,6 +995,7 @@ usemorebits='undef'
usemultiplicity='define'
usemymalloc='n'
usenm='false'
+usensgetexecutablepath='undef'
useopcode='true'
useperlio='undef'
useposix='true'
diff --git a/Porting/Glossary b/Porting/Glossary
index 1ed4ef87cb..81c83a9ef0 100644
--- a/Porting/Glossary
+++ b/Porting/Glossary
@@ -5053,6 +5053,11 @@ usenm (usenm.U):
This variable contains 'true' or 'false' depending whether the
nm extraction is wanted or not.
+usensgetexecutablepath (usensgetexecutablepath.U):
+ This symbol, if defined, indicates that we can use _NSGetExecutablePath
+ and realpath to get a full path for the executable, and hence convert
+ $^X to an absolute path.
+
useopcode (Extensions.U):
This variable holds either 'true' or 'false' to indicate
whether the Opcode extension should be used. The sole
diff --git a/Porting/config.sh b/Porting/config.sh
index 9244924dbd..fce318784e 100644
--- a/Porting/config.sh
+++ b/Porting/config.sh
@@ -1054,6 +1054,7 @@ usemorebits='undef'
usemultiplicity='undef'
usemymalloc='n'
usenm='false'
+usensgetexecutablepath='undef'
useopcode='true'
useperlio='define'
useposix='true'
diff --git a/config_h.SH b/config_h.SH
index 9281cddff0..7b8d31e6b5 100755
--- a/config_h.SH
+++ b/config_h.SH
@@ -2696,6 +2696,13 @@ sed <<!GROK!THIS! >$CONFIG_H -e 's!^#undef\(.*/\)\*!/\*#define\1 \*!' -e 's!^#un
*/
#$usekernprocpathname USE_KERN_PROC_PATHNAME /**/
+/* USE_NSGETEXECUTABLEPATH:
+ * This symbol, if defined, indicates that we can use _NSGetExecutablePath
+ * and realpath to get a full path for the executable, and hence convert
+ * $^X to an absolute path.
+ */
+#$usensgetexecutablepath USE_NSGETEXECUTABLEPATH /**/
+
/* Fpos_t:
* This symbol holds the type used to declare file positions in libc.
* It can be fpos_t, long, uint, etc... It may be necessary to include
diff --git a/configure.com b/configure.com
index a58f77e863..5da59730bc 100644
--- a/configure.com
+++ b/configure.com
@@ -6718,6 +6718,7 @@ $ WC "useieee='" + useieee + "'" ! VMS-specific
$ WC "useithreads='" + useithreads + "'"
$ WC "usekernelthreads='" + usekernelthreads + "'" ! VMS-specific
$ WC "usekernprocpathname='undef'"
+$ WC "usensgetexecutablepath='undef'"
$ WC "uselargefiles='" + uselargefiles + "'"
$ WC "uselongdouble='" + uselongdouble + "'"
$ WC "usemorebits='" + usemorebits + "'"
diff --git a/epoc/config.sh b/epoc/config.sh
index b71d62ea44..c80589005e 100644
--- a/epoc/config.sh
+++ b/epoc/config.sh
@@ -991,6 +991,7 @@ usemorebits='undef'
usemultiplicity='undef'
usemymalloc='n'
usenm=''
+usensgetexecutablepath='undef'
useopcode=''
useperlio='undef'
useposix=''
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);
diff --git a/plan9/config_sh.sample b/plan9/config_sh.sample
index b87320dfec..bd5da2fa14 100644
--- a/plan9/config_sh.sample
+++ b/plan9/config_sh.sample
@@ -1003,6 +1003,7 @@ usemorebits='undef'
usemultiplicity='undef'
usemymalloc='y'
usenm='false'
+usensgetexecutablepath='undef'
useopcode='true'
useperlio='define'
useposix='true'
diff --git a/symbian/config.sh b/symbian/config.sh
index c72d8c387a..a62577b820 100644
--- a/symbian/config.sh
+++ b/symbian/config.sh
@@ -818,6 +818,7 @@ usemorebits='undef'
usemultiplicity='undef'
usemymalloc='n'
usenm='false'
+usensgetexecutablepath='undef'
useopcode='true'
useperlio='define'
useposix='true'
diff --git a/t/op/magic.t b/t/op/magic.t
index 5569154fcd..8c2c508f57 100644
--- a/t/op/magic.t
+++ b/t/op/magic.t
@@ -230,7 +230,8 @@ $$ = $pid; # Tests below use $$
# $^X and $0
{
- my $is_abs = $Config{d_procselfexe} || $Config{usekernprocpathname};
+ my $is_abs = $Config{d_procselfexe} || $Config{usekernprocpathname}
+ || $Config{usensgetexecutablepath};
if ($^O eq 'qnx') {
chomp($wd = `/usr/bin/fullpath -t`);
}
diff --git a/uconfig.h b/uconfig.h
index c5f19f7e08..c3799020da 100644
--- a/uconfig.h
+++ b/uconfig.h
@@ -2663,6 +2663,13 @@
*/
/*#define USE_KERN_PROC_PATHNAME / **/
+/* USE_NSGETEXECUTABLEPATH:
+ * This symbol, if defined, indicates that we can use _NSGetExecutablePath
+ * and realpath to get a full path for the executable, and hence convert
+ * $^X to an absolute path.
+ */
+/*#define USE_NSGETEXECUTABLEPATH / **/
+
/* Fpos_t:
* This symbol holds the type used to declare file positions in libc.
* It can be fpos_t, long, uint, etc... It may be necessary to include
@@ -4711,6 +4718,6 @@
#endif
/* Generated from:
- * e6513dfa5f1449ab9266aee521d6d5908873d1dc68bf4f049316ebc4921732e1 config_h.SH
- * e940950d07a2be0354d6ae7e4316ec8465ed581607bbb958d8bfda024b9941fe uconfig.sh
+ * 5b5dacbb00f53ae9b440c79cf6d5c8bbf80a7adfa1db3f3814aa77dc6f461fa7 config_h.SH
+ * b5e74633486412bbc4d2a1c3847f3e85b10a86e96fb5d1efb7b8bc885956d746 uconfig.sh
* ex: set ro: */
diff --git a/uconfig.sh b/uconfig.sh
index ee84d35603..e7692dc693 100644
--- a/uconfig.sh
+++ b/uconfig.sh
@@ -785,6 +785,7 @@ usemorebits='undef'
usemultiplicity='undef'
usemymalloc='n'
usenm='false'
+usensgetexecutablepath='undef'
useopcode='true'
useperlio='undef'
useposix='true'
diff --git a/uconfig64.sh b/uconfig64.sh
index e3346e7787..1ae544fbcd 100644
--- a/uconfig64.sh
+++ b/uconfig64.sh
@@ -786,6 +786,7 @@ usemorebits='undef'
usemultiplicity='undef'
usemymalloc='n'
usenm='false'
+usensgetexecutablepath='undef'
useopcode='true'
useperlio='undef'
useposix='true'
diff --git a/win32/config.ce b/win32/config.ce
index 8028928dee..62d2123605 100644
--- a/win32/config.ce
+++ b/win32/config.ce
@@ -985,6 +985,7 @@ usemorebits='undef'
usemultiplicity='undef'
usemymalloc='n'
usenm='false'
+usensgetexecutablepath='undef'
useopcode='true'
useperlio='~USE_PERLIO~'
useposix='true'
diff --git a/win32/config.gc b/win32/config.gc
index ff6eb6f725..cb963fb6fa 100644
--- a/win32/config.gc
+++ b/win32/config.gc
@@ -1028,6 +1028,7 @@ usemorebits='undef'
usemultiplicity='undef'
usemymalloc='n'
usenm='false'
+usensgetexecutablepath='undef'
useopcode='true'
useperlio='undef'
useposix='true'
diff --git a/win32/config.gc64 b/win32/config.gc64
index e46b55af9d..7e06e2a9fd 100644
--- a/win32/config.gc64
+++ b/win32/config.gc64
@@ -1029,6 +1029,7 @@ usemorebits='undef'
usemultiplicity='undef'
usemymalloc='n'
usenm='false'
+usensgetexecutablepath='undef'
useopcode='true'
useperlio='undef'
useposix='true'
diff --git a/win32/config.gc64nox b/win32/config.gc64nox
index 82226e9cdd..92ef05f5a7 100644
--- a/win32/config.gc64nox
+++ b/win32/config.gc64nox
@@ -1029,6 +1029,7 @@ usemorebits='undef'
usemultiplicity='undef'
usemymalloc='n'
usenm='false'
+usensgetexecutablepath='undef'
useopcode='true'
useperlio='undef'
useposix='true'
diff --git a/win32/config.vc b/win32/config.vc
index f57805789c..379a125bab 100644
--- a/win32/config.vc
+++ b/win32/config.vc
@@ -1028,6 +1028,7 @@ usemorebits='undef'
usemultiplicity='undef'
usemymalloc='n'
usenm='false'
+usensgetexecutablepath='undef'
useopcode='true'
useperlio='undef'
useposix='true'
diff --git a/win32/config.vc64 b/win32/config.vc64
index 86b404044f..d429f2028c 100644
--- a/win32/config.vc64
+++ b/win32/config.vc64
@@ -1028,6 +1028,7 @@ usemorebits='undef'
usemultiplicity='undef'
usemymalloc='n'
usenm='false'
+usensgetexecutablepath='undef'
useopcode='true'
useperlio='undef'
useposix='true'