aboutsummaryrefslogtreecommitdiffstats
path: root/dir.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-08 01:58:44 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-08 01:58:44 +0000
commit720a15b7be589483e5977ef971b2407f2f6a1961 (patch)
tree6bda8194bbfdcdf54fab3e95ee338d5493c7087d /dir.c
parent3a4cb085800e76ae624c7fe985ccbeab0854d195 (diff)
downloadruby-720a15b7be589483e5977ef971b2407f2f6a1961.tar.gz
file.c: realpath in OS path encoding
* dir.c (rb_dir_getwd_ospath): return cwd path in the OS path encoding. * file.c (rb_realpath_internal): work in the OS path encoding git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/dir.c b/dir.c
index 25e6a9fccb..3f25bc576d 100644
--- a/dir.c
+++ b/dir.c
@@ -1082,37 +1082,52 @@ dir_s_chdir(int argc, VALUE *argv, VALUE obj)
}
VALUE
-rb_dir_getwd(void)
+rb_dir_getwd_ospath(void)
{
char *path;
VALUE cwd;
- rb_encoding *fs = rb_filesystem_encoding();
- int fsenc = rb_enc_to_index(fs);
VALUE path_guard;
#undef RUBY_UNTYPED_DATA_WARNING
#define RUBY_UNTYPED_DATA_WARNING 0
- if (fsenc == ENCINDEX_US_ASCII) fsenc = ENCINDEX_ASCII;
path_guard = Data_Wrap_Struct((VALUE)0, NULL, RUBY_DEFAULT_FREE, NULL);
path = my_getcwd();
DATA_PTR(path_guard) = path;
#ifdef _WIN32
- cwd = rb_str_conv_enc(rb_utf8_str_new_cstr(path), NULL, fs);
-#else
-#ifdef __APPLE__
+ cwd = rb_utf8_str_new_cstr(path);
+ OBJ_TAINT(cwd);
+#elif defined __APPLE__
cwd = rb_str_normalize_ospath(path, strlen(path));
OBJ_TAINT(cwd);
#else
cwd = rb_tainted_str_new2(path);
#endif
- rb_enc_associate_index(cwd, fsenc);
-#endif
DATA_PTR(path_guard) = 0;
xfree(path);
return cwd;
}
+VALUE
+rb_dir_getwd(void)
+{
+ rb_encoding *fs = rb_filesystem_encoding();
+ int fsenc = rb_enc_to_index(fs);
+ VALUE cwd = rb_dir_getwd_ospath();
+
+ switch (fsenc) {
+ case ENCINDEX_US_ASCII:
+ fsenc = ENCINDEX_ASCII;
+ case ENCINDEX_ASCII:
+ break;
+#if defined _WIN32 || defined __APPLE__
+ default:
+ return rb_str_conv_enc(cwd, NULL, fs);
+#endif
+ }
+ return rb_enc_associate_index(cwd, fsenc);
+}
+
/*
* call-seq:
* Dir.getwd -> string