summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-15 03:57:02 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-15 03:57:02 +0000
commitfcaee4bd64eb06ec4d0afd4e7e32ccf57acb5dc8 (patch)
tree79915a498af26746f5f1b1be60b90b7b1230b58d /hash.c
parentc6671f1005a19ee755c066fd882271afb86ccbbf (diff)
downloadruby-fcaee4bd64eb06ec4d0afd4e7e32ccf57acb5dc8.tar.gz
* win32/win32.c, include/ruby/win32.h (rb_w32_ugetenv): new API to
accept and to return UTF-8 strings. * win32/win32.c (rb_w32_getenv): follow above change. * win32/win32.c (rb_w32_get_environ): returns UTF-8 environment area. * hash.c (env_str_new, rb_f_getenv, env_fetch): follow above changes. [Bug #5570] [ruby-core:40737] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index 84a80bd086..ee703f59d4 100644
--- a/hash.c
+++ b/hash.c
@@ -2008,6 +2008,8 @@ static char **origenviron;
static char **my_environ;
#undef environ
#define environ my_environ
+#undef getenv
+#define getenv(n) rb_w32_ugetenv(n)
#elif defined(__APPLE__)
#undef environ
#define environ (*_NSGetEnviron())
@@ -2029,7 +2031,11 @@ extern char **environ;
static VALUE
env_str_new(const char *ptr, long len)
{
+#ifdef _WIN32
+ VALUE str = rb_str_encode(rb_enc_str_new(ptr, len, rb_utf8_encoding()), rb_enc_from_encoding(rb_locale_encoding()), 0, Qnil);
+#else
VALUE str = rb_locale_str_new(ptr, len);
+#endif
rb_obj_freeze(str);
return str;
@@ -2108,7 +2114,11 @@ rb_f_getenv(VALUE obj, VALUE name)
env = getenv(nam);
if (env) {
if (ENVMATCH(nam, PATH_ENV) && !env_path_tainted(env)) {
+#ifdef _WIN32
+ VALUE str = rb_str_encode(rb_enc_str_new(env, strlen(env), rb_utf8_encoding()), rb_enc_from_encoding(rb_filesystem_encoding()), 0, Qnil);
+#else
VALUE str = rb_filesystem_str_new_cstr(env);
+#endif
rb_obj_freeze(str);
return str;
@@ -2159,7 +2169,11 @@ env_fetch(int argc, VALUE *argv)
return if_none;
}
if (ENVMATCH(nam, PATH_ENV) && !env_path_tainted(env))
+#ifdef _WIN32
+ return rb_str_encode(rb_enc_str_new(env, strlen(env), rb_utf8_encoding()), rb_enc_from_encoding(rb_filesystem_encoding()), 0, Qnil);
+#else
return rb_filesystem_str_new_cstr(env);
+#endif
return env_str_new2(env);
}