Win32: Unicode arguments (outgoing)

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karsten Blees committed Jan 16, 2011 at 18:27 UTC 99c3c76d97164dba2cdd288281a0121de46f11e3
1 file changed +14 -4
compat/mingw.c
+14 -4
@@ -831,9 +831,10 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
831 const char *dir,
832 int prepend_cmd, int fhin, int fhout, int fherr)
833 {
834 - STARTUPINFO si;
834 + STARTUPINFOW si;
835 PROCESS_INFORMATION pi;
836 struct strbuf envblk, args;
837 + wchar_t wcmd[MAX_PATH], wdir[MAX_PATH], *wargs;
838 unsigned flags;
839 BOOL ret;
840
@@ -869,6 +870,11 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
870 si.hStdOutput = winansi_get_osfhandle(fhout);
871 si.hStdError = winansi_get_osfhandle(fherr);
872
873 + if (xutftowcs_path(wcmd, cmd) < 0)
874 + return -1;
875 + if (dir && xutftowcs_path(wdir, dir) < 0)
876 + return -1;
877 +
878 /* concatenate argv, quoting args as we go */
879 strbuf_init(&args, 0);
880 if (prepend_cmd) {
@@ -886,6 +892,10 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
892 free(quoted);
893 }
894
895 + wargs = xmalloc((2 * args.len + 1) * sizeof(wchar_t));
896 + xutftowcs(wargs, args.buf, 2 * args.len + 1);
897 + strbuf_release(&args);
898 +
899 if (env) {
900 int count = 0;
901 char **e, **sorted_env;
@@ -907,12 +917,12 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
917 }
918
919 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);
922
923 if (env)
924 strbuf_release(&envblk);
915 - strbuf_release(&args);
925 + free(wargs);
926
927 if (!ret) {
928 errno = ENOENT;