All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: Johannes Sixt <johannes.sixt@telecom.at>
Cc: git@vger.kernel.org
Subject: [MinGW PATCH] spawn*: default extension to .exe if none is given
Date: Mon, 31 Dec 2007 18:45:52 +0700	[thread overview]
Message-ID: <20071231114552.GA32421@laptop> (raw)

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

                 reply	other threads:[~2007-12-31 11:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071231114552.GA32421@laptop \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=johannes.sixt@telecom.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.