summaryrefslogtreecommitdiff
path: root/compat/mingw.c
diff options
context:
space:
mode:
authorKarsten Blees <blees@dcon.de>2014-07-17 17:37:56 +0200
committerJunio C Hamano <gitster@pobox.com>2014-07-21 09:32:48 -0700
commitb729f98fa50b10cfba7cbf3f37a0ac255e1fbdcd (patch)
treeb501979027cd75249e5dddec7712ec5ebf14b240 /compat/mingw.c
parent7eb2619c5cce7034cca1cdd07a090cbe648a3911 (diff)
downloadgit-b729f98fa50b10cfba7cbf3f37a0ac255e1fbdcd.tar.gz
Win32: Unicode environment (incoming)
Convert environment from UTF-16 to UTF-8 on startup. No changes to getenv() are necessary, as the MSVCRT version is implemented on top of char **environ. However, putenv / _wputenv from MSVCRT no longer work, for two reasons: 1. they try to keep environ, _wenviron and the Win32 process environment in sync, using the default system encoding instead of UTF-8 to convert between charsets 2. msysgit and MSVCRT use different allocators, memory allocated in git cannot be freed by the CRT and vice versa Implement mingw_putenv using the env_setenv helper function from the environment merge code. Note that in case of memory allocation failure, putenv now dies with error message (due to xrealloc) instead of failing with ENOMEM. As git assumes setenv / putenv to always succeed, this prevents it from continuing with incorrect settings. 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>
Diffstat (limited to 'compat/mingw.c')
-rw-r--r--compat/mingw.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index c725a3e206..cb0914af6c 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1260,6 +1260,12 @@ char *mingw_getenv(const char *name)
return result;
}
+int mingw_putenv(const char *namevalue)
+{
+ environ = env_setenv(environ, namevalue);
+ return 0;
+}
+
/*
* Note, this isn't a complete replacement for getaddrinfo. It assumes
* that service contains a numerical port, or that it is null. It
@@ -2052,6 +2058,11 @@ void mingw_startup()
maxlen = wcslen(_wpgmptr);
for (i = 1; i < argc; i++)
maxlen = max(maxlen, wcslen(wargv[i]));
+ for (i = 0; wenv[i]; i++)
+ maxlen = max(maxlen, wcslen(wenv[i]));
+
+ /* nedmalloc can't free CRT memory, allocate resizable environment list */
+ environ = xcalloc(i + 1, sizeof(char*));
/* allocate buffer (wchar_t encodes to max 3 UTF-8 bytes) */
maxlen = 3 * maxlen + 1;
@@ -2064,6 +2075,10 @@ void mingw_startup()
len = xwcstoutf(buffer, wargv[i], maxlen);
__argv[i] = xmemdupz(buffer, len);
}
+ for (i = 0; wenv[i]; i++) {
+ len = xwcstoutf(buffer, wenv[i], maxlen);
+ environ[i] = xmemdupz(buffer, len);
+ }
free(buffer);
/* initialize critical section for waitpid pinfo_t list */