Win32: Unicode environment (outgoing)
Convert environment 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
Jul 17, 2014 at 17:37 UTC
7eb2619c5cce7034cca1cdd07a090cbe648a3911
1 file changed
+14
-11
compat/mingw.c
+14
-11
@@ -4,6 +4,7 @@
4
#include <wchar.h>
5
#include "../strbuf.h"
6
#include "../run-command.h"
7
+#include "../cache.h"
8
9
static const int delay[] = { 0, 1, 10, 20, 40 };
10
@@ -919,9 +920,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
920
{
921
STARTUPINFOW si;
922
PROCESS_INFORMATION pi;
922
- struct strbuf envblk, args;
923
- wchar_t wcmd[MAX_PATH], wdir[MAX_PATH], *wargs;
924
- unsigned flags;
923
+ struct strbuf args;
924
+ wchar_t wcmd[MAX_PATH], wdir[MAX_PATH], *wargs, *wenvblk = NULL;
925
+ unsigned flags = CREATE_UNICODE_ENVIRONMENT;
926
BOOL ret;
927
928
/* Determine whether or not we are associated to a console */
@@ -938,7 +939,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
939
* instead of CREATE_NO_WINDOW to make ssh
940
* recognize that it has no console.
941
*/
941
- flags = DETACHED_PROCESS;
942
+ flags |= DETACHED_PROCESS;
943
} else {
944
/* There is already a console. If we specified
945
* DETACHED_PROCESS here, too, Windows would
@@ -946,7 +947,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
947
* The same is true for CREATE_NO_WINDOW.
948
* Go figure!
949
*/
949
- flags = 0;
950
CloseHandle(cons);
951
}
952
memset(&si, 0, sizeof(si));
@@ -985,6 +985,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
985
if (env) {
986
int count = 0;
987
char **e, **sorted_env;
988
+ int size = 0, wenvsz = 0, wenvpos = 0;
989
990
for (e = env; *e; e++)
991
count++;
@@ -994,20 +995,22 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
995
memcpy(sorted_env, env, sizeof(*sorted_env) * (count + 1));
996
qsort(sorted_env, count, sizeof(*sorted_env), env_compare);
997
997
- strbuf_init(&envblk, 0);
998
+ /* create environment block from temporary environment */
999
for (e = sorted_env; *e; e++) {
999
- strbuf_addstr(&envblk, *e);
1000
- strbuf_addch(&envblk, '\0');
1000
+ size = 2 * strlen(*e) + 2; /* +2 for final \0 */
1001
+ ALLOC_GROW(wenvblk, (wenvpos + size) * sizeof(wchar_t), wenvsz);
1002
+ wenvpos += xutftowcs(&wenvblk[wenvpos], *e, size) + 1;
1003
}
1004
+ /* add final \0 terminator */
1005
+ wenvblk[wenvpos] = 0;
1006
free(sorted_env);
1007
}
1008
1009
memset(&pi, 0, sizeof(pi));
1010
ret = CreateProcessW(wcmd, wargs, NULL, NULL, TRUE, flags,
1007
- env ? envblk.buf : NULL, dir ? wdir : NULL, &si, &pi);
1011
+ wenvblk, dir ? wdir : NULL, &si, &pi);
1012
1009
- if (env)
1010
- strbuf_release(&envblk);
1013
+ free(wenvblk);
1014
free(wargs);
1015
1016
if (!ret) {