summaryrefslogtreecommitdiff
path: root/compat/mingw.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-11-13 13:37:21 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-11-13 13:37:21 (GMT)
commit0474cd19ef55c02d026e9a5b75c086bf8afbad40 (patch)
tree0bbf5012dcd7137175dcdb0396ba2837b07f87d1 /compat/mingw.h
parent6c268fdda9dcc421e2bee1ce76496d3e9f96397f (diff)
parentfe21c6b285df4088f9685d5deed425064367ea24 (diff)
downloadgit-0474cd19ef55c02d026e9a5b75c086bf8afbad40.zip
git-0474cd19ef55c02d026e9a5b75c086bf8afbad40.tar.gz
git-0474cd19ef55c02d026e9a5b75c086bf8afbad40.tar.bz2
Merge branch 'js/mingw-utf8-env'
Windows fix. * js/mingw-utf8-env: mingw: reencode environment variables on the fly (UTF-16 <-> UTF-8) t7800: fix quoting
Diffstat (limited to 'compat/mingw.h')
-rw-r--r--compat/mingw.h32
1 files changed, 28 insertions, 4 deletions
diff --git a/compat/mingw.h b/compat/mingw.h
index 2f1f8e3..8c24dda 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -260,11 +260,35 @@ char *mingw_mktemp(char *template);
char *mingw_getcwd(char *pointer, int len);
#define getcwd mingw_getcwd
+#ifdef NO_UNSETENV
+#error "NO_UNSETENV is incompatible with the Windows-specific startup code!"
+#endif
+
+/*
+ * We bind *env() routines (even the mingw_ ones) to private mingw_ versions.
+ * These talk to the CRT using UNICODE/wchar_t, but maintain the original
+ * narrow-char API.
+ *
+ * Note that the MSCRT maintains both ANSI (getenv()) and UNICODE (_wgetenv())
+ * routines and stores both versions of each environment variable in parallel
+ * (and secretly updates both when you set one or the other), but it uses CP_ACP
+ * to do the conversion rather than CP_UTF8.
+ *
+ * Since everything in the git code base is UTF8, we define the mingw_ routines
+ * to access the CRT using the UNICODE routines and manually convert them to
+ * UTF8. This also avoids round-trip problems.
+ *
+ * This also helps with our linkage, since "_wenviron" is publicly exported
+ * from the CRT. But to access "_environ" we would have to statically link
+ * to the CRT (/MT).
+ *
+ * We require NO_SETENV (and let gitsetenv() call our mingw_putenv).
+ */
+#define getenv mingw_getenv
+#define putenv mingw_putenv
+#define unsetenv mingw_putenv
char *mingw_getenv(const char *name);
-#define getenv mingw_getenv
-int mingw_putenv(const char *namevalue);
-#define putenv mingw_putenv
-#define unsetenv mingw_putenv
+int mingw_putenv(const char *name);
int mingw_gethostname(char *host, int namelen);
#define gethostname mingw_gethostname