perl/perl-5.29.3-RT-133573-X-fallback-when-platform-specific-techniqu.patch
2019-01-15 10:33:18 +01:00

78 lines
2.2 KiB
Diff

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