Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 82d17a5

Browse files
kbleeskasal
authored andcommitted
Win32: Unicode arguments (outgoing)
Convert command line arguments from UTF-8 to UTF-16 when creating other processes. Signed-off-by: Karsten Blees <[email protected]>
1 parent 7ae13e6 commit 82d17a5

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

compat/mingw.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -931,9 +931,10 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
931931
const char *dir,
932932
int prepend_cmd, int fhin, int fhout, int fherr)
933933
{
934-
STARTUPINFO si;
934+
STARTUPINFOW si;
935935
PROCESS_INFORMATION pi;
936936
struct strbuf envblk, args;
937+
wchar_t wcmd[MAX_PATH], wdir[MAX_PATH], *wargs;
937938
unsigned flags;
938939
BOOL ret;
939940

@@ -969,6 +970,11 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
969970
si.hStdOutput = winansi_get_osfhandle(fhout);
970971
si.hStdError = winansi_get_osfhandle(fherr);
971972

973+
if (xutftowcs_path(wcmd, cmd) < 0)
974+
return -1;
975+
if (dir && xutftowcs_path(wdir, dir) < 0)
976+
return -1;
977+
972978
/* concatenate argv, quoting args as we go */
973979
strbuf_init(&args, 0);
974980
if (prepend_cmd) {
@@ -986,6 +992,10 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
986992
free(quoted);
987993
}
988994

995+
wargs = xmalloc((2 * args.len + 1) * sizeof(wchar_t));
996+
xutftowcs(wargs, args.buf, 2 * args.len + 1);
997+
strbuf_release(&args);
998+
989999
if (env) {
9901000
int count = 0;
9911001
char **e, **sorted_env;
@@ -1007,12 +1017,12 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
10071017
}
10081018

10091019
memset(&pi, 0, sizeof(pi));
1010-
ret = CreateProcess(cmd, args.buf, NULL, NULL, TRUE, flags,
1011-
env ? envblk.buf : NULL, dir, &si, &pi);
1020+
ret = CreateProcessW(wcmd, wargs, NULL, NULL, TRUE, flags,
1021+
env ? envblk.buf : NULL, dir ? wdir : NULL, &si, &pi);
10121022

10131023
if (env)
10141024
strbuf_release(&envblk);
1015-
strbuf_release(&args);
1025+
free(wargs);
10161026

10171027
if (!ret) {
10181028
errno = ENOENT;

0 commit comments

Comments
 (0)