Skip to contentSkip to conversation

spawn*: default extension to .exe if none is given

PATCH New Nguyễn Thái Ngọc Duy 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spawn*: default extension to .exe if none is given

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

---
 compat/mingw.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)
compat/mingw.c +18 -1
index 8bbe21b..dc54303 100644
@@ -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;
Signature · 1 line
1.5.4.rc2.1097.gb6e0d