git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Dec 31, 2007, 11:45 UTC
Message-ID
<20071231114552.GA32421@laptop>

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@gmail.com>
---
 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
Message 1 of 1 in “spawn*: default extension to .exe if none is given”
  1. spawn*: default extension to .exe if none is givenNguyễn Thái Ngọc Duy, Dec 31, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.