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

[PATCH 5/7] Win32: Unicode arguments (outgoing)

From
Stepan Kasal <kasal@ucw.cz>
Date
Jun 11, 2014, 09:37 UTC
Message-ID
<1402479466-8500-6-git-send-email-kasal@ucw.cz>
In-Reply-To
<1402479466-8500-1-git-send-email-kasal@ucw.cz>
From: Karsten Blees <blees@dcon.de>
Date: Sun, 16 Jan 2011 18:27:53 +0100

Convert command line arguments from UTF-8 to UTF-16 when creating other processes.

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index 1140a13..8a7b047 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -831,9 +831,10 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
 			      const char *dir,
 			      int prepend_cmd, int fhin, int fhout, int fherr)
 {
-	STARTUPINFO si;
+	STARTUPINFOW si;
 	PROCESS_INFORMATION pi;
 	struct strbuf envblk, args;
+	wchar_t wcmd[MAX_PATH], wdir[MAX_PATH], *wargs;
 	unsigned flags;
 	BOOL ret;
 
@@ -869,6 +870,11 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
 	si.hStdOutput = winansi_get_osfhandle(fhout);
 	si.hStdError = winansi_get_osfhandle(fherr);
 
+	if (xutftowcs_path(wcmd, cmd) < 0)
+		return -1;
+	if (dir && xutftowcs_path(wdir, dir) < 0)
+		return -1;
+
 	/* concatenate argv, quoting args as we go */
 	strbuf_init(&args, 0);
 	if (prepend_cmd) {
@@ -886,6 +892,10 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
 			free(quoted);
 	}
 
+	wargs = xmalloc((2 * args.len + 1) * sizeof(wchar_t));
+	xutftowcs(wargs, args.buf, 2 * args.len + 1);
+	strbuf_release(&args);
+
 	if (env) {
 		int count = 0;
 		char **e, **sorted_env;
@@ -907,12 +917,12 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
 	}
 
 	memset(&pi, 0, sizeof(pi));
-	ret = CreateProcess(cmd, args.buf, NULL, NULL, TRUE, flags,
-		env ? envblk.buf : NULL, dir, &si, &pi);
+	ret = CreateProcessW(wcmd, wargs, NULL, NULL, TRUE, flags,
+		env ? envblk.buf : NULL, dir ? wdir : NULL, &si, &pi);
 
 	if (env)
 		strbuf_release(&envblk);
-	strbuf_release(&args);
+	free(wargs);
 
 	if (!ret) {
 		errno = ENOENT;
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Previous: Stepan KasalNext: Stepan Kasal
Message 6 of 12 in “Second part of msysgit/unicode”
  1. 0/7 Second part of msysgit/unicodeStepan Kasal, Jun 11, 2014
  2. 1/7 Let mingw_execve() return an intStepan Kasal, Jun 11, 2014
  3. 2/7 Win32: simplify internal mingw_spawn* APIsStepan Kasal, Jun 11, 2014
  4. 3/7 Win32: fix potential multi-threading issueStepan Kasal, Jun 11, 2014
  5. 4/7 MinGW: disable CRT command line globbingStepan Kasal, Jun 11, 2014
  6. 5/7 Win32: Unicode arguments (outgoing)Stepan Kasal, Jun 11, 2014
  7. 6/7 Win32: Unicode arguments (incoming)Stepan Kasal, Jun 11, 2014
  8. 7/7 Unicode file name support (gitk and git-gui)Stepan Kasal, Jun 11, 2014
  9. Karsten BleesJun 17, 2014
  10. Stepan KasalJun 18, 2014
  11. Junio C HamanoJun 18, 2014
  12. Johannes SixtJun 18, 2014

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.