Skip to content

Commit

Permalink
Win32: Unicode arguments (outgoing)
Browse files Browse the repository at this point in the history
Convert command line arguments from UTF-8 to UTF-16 when creating other
processes.

Signed-off-by: Karsten Blees <blees@dcon.de>
  • Loading branch information
kblees committed Mar 15, 2012
1 parent 16de786 commit 0a8d0ef
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions compat/mingw.c
Expand Up @@ -955,9 +955,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;

Expand Down Expand Up @@ -993,6 +994,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) {
Expand All @@ -1010,6 +1016,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;
Expand All @@ -1031,12 +1041,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;
Expand Down

0 comments on commit 0a8d0ef

Please sign in to comment.