[MinGW PATCH] spawn*: default extension to .exe if none is given

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is the behavior of spawn* (or at least Wine source does it).
CreateProcess() does not have such assumption.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 compat/mingw.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index 8bbe21b..dc54303 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -533,8 +533,9 @@ static pid_t mingw_spawnve(const char *cmd, const char **argv, char **env,
 {
 	STARTUPINFO si;
 	PROCESS_INFORMATION pi;
-	struct strbuf envblk, args;
+	struct strbuf envblk, args, newcmd;
 	unsigned flags;
+	const char *basename;
 	BOOL ret;
 
 	/* Determine whether or not we are associated to a console */
@@ -565,6 +566,21 @@ static pid_t mingw_spawnve(const char *cmd, const char **argv, char **env,
 	si.hStdOutput = (HANDLE) _get_osfhandle(1);
 	si.hStdError = (HANDLE) _get_osfhandle(2);
 
+	/* Assume .exe if there is no extension */
+	strbuf_init(&newcmd, 0);
+	basename = strrchr(cmd, '/');
+	if (strrchr(cmd, '\\') > basename)
+		basename = strrchr(cmd, '\\');
+	if (basename)
+		basename ++;
+	else
+		basename = cmd;
+	if (!strchr(basename, '.')) {
+		strbuf_addstr(&newcmd, cmd);
+		strbuf_addstr(&newcmd, ".exe");
+		cmd = newcmd.buf;
+	}
+
 	/* concatenate argv, quoting args as we go */
 	strbuf_init(&args, 0);
 	if (prepend_cmd) {
@@ -609,6 +625,7 @@ static pid_t mingw_spawnve(const char *cmd, const char **argv, char **env,
 	if (env)
 		strbuf_release(&envblk);
 	strbuf_release(&args);
+	strbuf_release(&newcmd);
 
 	if (!ret) {
 		errno = ENOENT;
-- 
1.5.4.rc2.1097.gb6e0d
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux