Created
December 16, 2011 15:02
-
-
Save koron/1486374 to your computer and use it in GitHub Desktop.
vim: encoding sensitive setenv() for windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HG changeset patch | |
# Parent 622b4fb33b85d68a98fd1c4d209e105b3ddecef7 | |
convert encoding of environment value when mismatch between Vim and OS | |
diff -r 622b4fb33b85 src/os_win32.c | |
--- a/src/os_win32.c Fri Dec 16 09:14:12 2011 +0900 | |
+++ b/src/os_win32.c Fri Dec 16 23:58:48 2011 +0900 | |
@@ -5816,3 +5816,34 @@ | |
set_alist_count(); | |
} | |
#endif | |
+ | |
+ int | |
+mch_setenv(var, value, x) | |
+ char *var; | |
+ char *value; | |
+ int x; | |
+{ | |
+ char_u *envbuf; | |
+ | |
+ envbuf = alloc((unsigned)(STRLEN(var) + STRLEN(value) + 2)); | |
+ if (envbuf == NULL) | |
+ return -1; | |
+ | |
+ sprintf((char *)envbuf, "%s=%s", var, value); | |
+ | |
+#ifdef FEAT_MBYTE | |
+ if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
+ { | |
+ WCHAR *p = enc_to_utf16(envbuf, NULL); | |
+ | |
+ vim_free(envbuf); | |
+ if (p == NULL) | |
+ return -1; | |
+ _wputenv(p); | |
+ } | |
+ else | |
+#endif | |
+ _putenv((char *)envbuf); | |
+ | |
+ return 0; | |
+} | |
diff -r 622b4fb33b85 src/os_win32.h | |
--- a/src/os_win32.h Fri Dec 16 09:14:12 2011 +0900 | |
+++ b/src/os_win32.h Fri Dec 16 23:58:48 2011 +0900 | |
@@ -187,7 +187,9 @@ | |
#define ASSERT_NULL_OR_POINTER(p, type) \ | |
ASSERT(((p) == NULL) || IsValidAddress((p), sizeof(type), FALSE)) | |
-#define mch_setenv(name, val, x) setenv(name, val, x) | |
+#ifndef HAVE_SETENV | |
+# define HAVE_SETENV | |
+#endif | |
#define mch_getenv(x) (char_u *)getenv((char *)(x)) | |
#ifdef __BORLANDC__ | |
# define vim_mkdir(x, y) mkdir(x) | |
diff -r 622b4fb33b85 src/proto/os_win32.pro | |
--- a/src/proto/os_win32.pro Fri Dec 16 09:14:12 2011 +0900 | |
+++ b/src/proto/os_win32.pro Fri Dec 16 23:58:48 2011 +0900 | |
@@ -54,4 +54,5 @@ | |
void used_file_arg __ARGS((char *name, int literal, int full_path, int diff_mode)); | |
void set_alist_count __ARGS((void)); | |
void fix_arg_enc __ARGS((void)); | |
+int mch_setenv __ARGS((char *var, char *value, int x)); | |
/* vim: set ft=c : */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment