Created
January 25, 2013 14:51
-
-
Save ynkdir/4634974 to your computer and use it in GitHub Desktop.
wsetenv and wgetenv
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
diff -r 3bc0838d3188 src/misc1.c | |
--- a/src/misc1.c Thu Jan 24 21:00:20 2013 +0100 | |
+++ b/src/misc1.c Fri Jan 25 23:38:13 2013 +0900 | |
@@ -3738,23 +3738,6 @@ | |
} | |
} | |
} | |
- | |
-# if defined(FEAT_MBYTE) | |
- if (enc_utf8 && var != NULL) | |
- { | |
- int len; | |
- char_u *pp = NULL; | |
- | |
- /* Convert from active codepage to UTF-8. Other conversions are | |
- * not done, because they would fail for non-ASCII characters. */ | |
- acp_to_enc(var, (int)STRLEN(var), &pp, &len); | |
- if (pp != NULL) | |
- { | |
- homedir = pp; | |
- return; | |
- } | |
- } | |
-# endif | |
#endif | |
#if defined(OS2) || defined(MSDOS) || defined(MSWIN) | |
@@ -4141,25 +4124,7 @@ | |
p = NULL; | |
if (p != NULL) | |
- { | |
-#if defined(FEAT_MBYTE) && defined(WIN3264) | |
- if (enc_utf8) | |
- { | |
- int len; | |
- char_u *pp = NULL; | |
- | |
- /* Convert from active codepage to UTF-8. Other conversions are | |
- * not done, because they would fail for non-ASCII characters. */ | |
- acp_to_enc(p, (int)STRLEN(p), &pp, &len); | |
- if (pp != NULL) | |
- { | |
- p = pp; | |
- *mustfree = TRUE; | |
- } | |
- } | |
-#endif | |
return p; | |
- } | |
vimruntime = (STRCMP(name, "VIMRUNTIME") == 0); | |
if (!vimruntime && STRCMP(name, "VIM") != 0) | |
@@ -4185,26 +4150,6 @@ | |
*mustfree = TRUE; | |
else | |
p = mch_getenv((char_u *)"VIM"); | |
- | |
-#if defined(FEAT_MBYTE) && defined(WIN3264) | |
- if (enc_utf8) | |
- { | |
- int len; | |
- char_u *pp = NULL; | |
- | |
- /* Convert from active codepage to UTF-8. Other conversions | |
- * are not done, because they would fail for non-ASCII | |
- * characters. */ | |
- acp_to_enc(p, (int)STRLEN(p), &pp, &len); | |
- if (pp != NULL) | |
- { | |
- if (*mustfree) | |
- vim_free(p); | |
- p = pp; | |
- *mustfree = TRUE; | |
- } | |
- } | |
-#endif | |
} | |
} | |
diff -r 3bc0838d3188 src/os_win32.c | |
--- a/src/os_win32.c Thu Jan 24 21:00:20 2013 +0100 | |
+++ b/src/os_win32.c Fri Jan 25 23:38:13 2013 +0900 | |
@@ -5947,3 +5947,65 @@ | |
set_alist_count(); | |
} | |
#endif | |
+ | |
+ char_u * | |
+mch_getenv(char_u *var) | |
+{ | |
+#ifdef FEAT_MBYTE | |
+ WCHAR *wvar; | |
+ WCHAR *wval; | |
+ static char_u *alloced = NULL; | |
+ | |
+ if (alloced != NULL) | |
+ { | |
+ vim_free(alloced); | |
+ alloced = NULL; | |
+ } | |
+ | |
+ if (enc_utf8) | |
+ { | |
+ wvar = enc_to_utf16(var, NULL); | |
+ if (wvar != NULL) | |
+ { | |
+ wval = _wgetenv(wvar); | |
+ if (wval != NULL) | |
+ alloced = utf16_to_enc(wval, NULL); | |
+ vim_free(wvar); | |
+ return alloced; | |
+ } | |
+ } | |
+#endif | |
+ | |
+ return (char_u *)getenv((char *)var); | |
+} | |
+ | |
+ 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 3bc0838d3188 src/os_win32.h | |
--- a/src/os_win32.h Thu Jan 24 21:00:20 2013 +0100 | |
+++ b/src/os_win32.h Fri Jan 25 23:38:13 2013 +0900 | |
@@ -191,8 +191,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) | |
-#define mch_getenv(x) (char_u *)getenv((char *)(x)) | |
+#ifndef HAVE_SETENV | |
+# define HAVE_SETENV | |
+#endif | |
#ifdef __BORLANDC__ | |
# define vim_mkdir(x, y) mkdir(x) | |
#else | |
diff -r 3bc0838d3188 src/proto/os_win32.pro | |
--- a/src/proto/os_win32.pro Thu Jan 24 21:00:20 2013 +0100 | |
+++ b/src/proto/os_win32.pro Fri Jan 25 23:38:13 2013 +0900 | |
@@ -54,4 +54,6 @@ | |
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)); | |
+char_u *mch_getenv __ARGS((char_u *var)); | |
+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