|
|
cee3144 |
From 03b94aa47e981af3c7b0118bfb11facda2b95251 Mon Sep 17 00:00:00 2001
|
|
|
cee3144 |
From: Aaron Crane <arc@cpan.org>
|
|
|
cee3144 |
Date: Tue, 9 Oct 2018 14:41:10 +0100
|
|
|
cee3144 |
Subject: [PATCH] RT#133573: $^X fallback when platform-specific technique
|
|
|
cee3144 |
fails
|
|
|
cee3144 |
MIME-Version: 1.0
|
|
|
cee3144 |
Content-Type: text/plain; charset=UTF-8
|
|
|
cee3144 |
Content-Transfer-Encoding: 8bit
|
|
|
cee3144 |
|
|
|
cee3144 |
Signed-off-by: Petr Písař <ppisar@redhat.com>
|
|
|
cee3144 |
---
|
|
|
cee3144 |
caretx.c | 28 ++++++++++++++++------------
|
|
|
cee3144 |
1 file changed, 16 insertions(+), 12 deletions(-)
|
|
|
cee3144 |
|
|
|
cee3144 |
diff --git a/caretx.c b/caretx.c
|
|
|
cee3144 |
index d758f730de..247708de8c 100644
|
|
|
cee3144 |
--- a/caretx.c
|
|
|
cee3144 |
+++ b/caretx.c
|
|
|
cee3144 |
@@ -56,7 +56,19 @@ Perl_set_caret_X(pTHX) {
|
|
|
cee3144 |
SV *const caret_x = GvSV(tmpgv);
|
|
|
cee3144 |
#if defined(OS2)
|
|
|
cee3144 |
sv_setpv(caret_x, os2_execname(aTHX));
|
|
|
cee3144 |
-#elif defined(USE_KERN_PROC_PATHNAME)
|
|
|
cee3144 |
+ return;
|
|
|
cee3144 |
+#elif defined(WIN32)
|
|
|
cee3144 |
+ char *ansi;
|
|
|
cee3144 |
+ WCHAR widename[MAX_PATH];
|
|
|
cee3144 |
+ GetModuleFileNameW(NULL, widename, sizeof(widename)/sizeof(WCHAR));
|
|
|
cee3144 |
+ ansi = win32_ansipath(widename);
|
|
|
cee3144 |
+ sv_setpv(caret_x, ansi);
|
|
|
cee3144 |
+ win32_free(ansi);
|
|
|
cee3144 |
+ return;
|
|
|
cee3144 |
+#else
|
|
|
cee3144 |
+ /* We can try a platform-specific one if possible; if it fails, or we
|
|
|
cee3144 |
+ * aren't running on a suitable platform, we'll fall back to argv[0]. */
|
|
|
cee3144 |
+# ifdef USE_KERN_PROC_PATHNAME
|
|
|
cee3144 |
size_t size = 0;
|
|
|
cee3144 |
int mib[4];
|
|
|
cee3144 |
mib[0] = CTL_KERN;
|
|
|
cee3144 |
@@ -76,7 +88,7 @@ Perl_set_caret_X(pTHX) {
|
|
|
cee3144 |
return;
|
|
|
cee3144 |
}
|
|
|
cee3144 |
}
|
|
|
cee3144 |
-#elif defined(USE_NSGETEXECUTABLEPATH)
|
|
|
cee3144 |
+# elif defined(USE_NSGETEXECUTABLEPATH)
|
|
|
cee3144 |
char buf[1];
|
|
|
cee3144 |
uint32_t size = sizeof(buf);
|
|
|
cee3144 |
|
|
|
cee3144 |
@@ -95,7 +107,7 @@ Perl_set_caret_X(pTHX) {
|
|
|
cee3144 |
return;
|
|
|
cee3144 |
}
|
|
|
cee3144 |
}
|
|
|
cee3144 |
-#elif defined(HAS_PROCSELFEXE)
|
|
|
cee3144 |
+# elif defined(HAS_PROCSELFEXE)
|
|
|
cee3144 |
char buf[MAXPATHLEN];
|
|
|
cee3144 |
SSize_t len = readlink(PROCSELFEXE_PATH, buf, sizeof(buf) - 1);
|
|
|
cee3144 |
/* NOTE: if the length returned by readlink() is sizeof(buf) - 1,
|
|
|
cee3144 |
@@ -125,15 +137,7 @@ Perl_set_caret_X(pTHX) {
|
|
|
cee3144 |
sv_setpvn(caret_x, buf, len);
|
|
|
cee3144 |
return;
|
|
|
cee3144 |
}
|
|
|
cee3144 |
-#elif defined(WIN32)
|
|
|
cee3144 |
- char *ansi;
|
|
|
cee3144 |
- WCHAR widename[MAX_PATH];
|
|
|
cee3144 |
- GetModuleFileNameW(NULL, widename, sizeof(widename)/sizeof(WCHAR));
|
|
|
cee3144 |
- ansi = win32_ansipath(widename);
|
|
|
cee3144 |
- sv_setpv(caret_x, ansi);
|
|
|
cee3144 |
- win32_free(ansi);
|
|
|
cee3144 |
- return;
|
|
|
cee3144 |
-#else
|
|
|
cee3144 |
+# endif
|
|
|
cee3144 |
/* Fallback to this: */
|
|
|
cee3144 |
sv_setpv(caret_x, PL_origargv[0]);
|
|
|
cee3144 |
#endif
|
|
|
cee3144 |
--
|
|
|
cee3144 |
2.17.2
|
|
|
cee3144 |
|