summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-08 01:58:44 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-08 01:58:44 (GMT)
commitaac0b43ed583f5091faa3a323261090766de566c (patch)
tree6bda8194bbfdcdf54fab3e95ee338d5493c7087d /dir.c
parent6502c038157f7357c9e06a1446029a24f3bb8fcb (diff)
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 25e6a9f..3f25bc5 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