Skip to content

Commit 99c3c76

Browse files
kbleesgitster
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]> Signed-off-by: Stepan Kasal <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5901dc6 commit 99c3c76

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
@@ -831,9 +831,10 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
831831
const char *dir,
832832
int prepend_cmd, int fhin, int fhout, int fherr)
833833
{
834-
STARTUPINFO si;
834+
STARTUPINFOW si;
835835
PROCESS_INFORMATION pi;
836836
struct strbuf envblk, args;
837+
wchar_t wcmd[MAX_PATH], wdir[MAX_PATH], *wargs;
837838
unsigned flags;
838839
BOOL ret;
839840

@@ -869,6 +870,11 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
869870
si.hStdOutput = winansi_get_osfhandle(fhout);
870871
si.hStdError = winansi_get_osfhandle(fherr);
871872

873+
if (xutftowcs_path(wcmd, cmd) < 0)
874+
return -1;
875+
if (dir && xutftowcs_path(wdir, dir) < 0)
876+
return -1;
877+
872878
/* concatenate argv, quoting args as we go */
873879
strbuf_init(&args, 0);
874880
if (prepend_cmd) {
@@ -886,6 +892,10 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
886892
free(quoted);
887893
}
888894

895+
wargs = xmalloc((2 * args.len + 1) * sizeof(wchar_t));
896+
xutftowcs(wargs, args.buf, 2 * args.len + 1);
897+
strbuf_release(&args);
898+
889899
if (env) {
890900
int count = 0;
891901
char **e, **sorted_env;
@@ -907,12 +917,12 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
907917
}
908918

909919
memset(&pi, 0, sizeof(pi));
910-
ret = CreateProcess(cmd, args.buf, NULL, NULL, TRUE, flags,
911-
env ? envblk.buf : NULL, dir, &si, &pi);
920+
ret = CreateProcessW(wcmd, wargs, NULL, NULL, TRUE, flags,
921+
env ? envblk.buf : NULL, dir ? wdir : NULL, &si, &pi);
912922

913923
if (env)
914924
strbuf_release(&envblk);
915-
strbuf_release(&args);
925+
free(wargs);
916926

917927
if (!ret) {
918928
errno = ENOENT;

0 commit comments

Comments
 (0)