summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-18 03:57:37 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-18 03:57:37 +0000
commit3c5452dba11cc909252eaa97c83f7a31c3a230a6 (patch)
tree6d0a443af69f74daaffb08d6ebca3017d4cc8e6f /file.c
parent2171d75e9bd14409d62fcc5a8acdbb2ec1c23060 (diff)
revert r62797, r62784. [Bug #13863]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@62801 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c34
1 files changed, 10 insertions, 24 deletions
diff --git a/file.c b/file.c
index 43040787d0..0e67654da2 100644
--- a/file.c
+++ b/file.c
@@ -126,14 +126,6 @@ int flock(int, int);
#define STAT(p, s) stat((p), (s))
#endif
-#if defined _WIN32 || defined __APPLE__
-# define USE_OSPATH 1
-# define TO_OSPATH(str) rb_str_encode_ospath(str)
-#else
-# define USE_OSPATH 0
-# define TO_OSPATH(str) (str)
-#endif
-
VALUE rb_cFile;
VALUE rb_mFileTest;
VALUE rb_cStat;
@@ -230,7 +222,7 @@ rb_get_path(VALUE obj)
VALUE
rb_str_encode_ospath(VALUE path)
{
-#if USE_OSPATH
+#if defined _WIN32 || defined __APPLE__
int encidx = ENCODING_GET(path);
#ifdef _WIN32
if (encidx == ENCINDEX_ASCII) {
@@ -3841,10 +3833,11 @@ realpath_rec(long *prefixlenp, VALUE *resolvedp, const char *unresolved,
else {
struct stat sbuf;
int ret;
+ VALUE testpath2 = rb_str_encode_ospath(testpath);
#ifdef __native_client__
- ret = stat(RSTRING_PTR(testpath), &sbuf);
+ ret = stat(RSTRING_PTR(testpath2), &sbuf);
#else
- ret = lstat(RSTRING_PTR(testpath), &sbuf);
+ ret = lstat(RSTRING_PTR(testpath2), &sbuf);
#endif
if (ret == -1) {
int e = errno;
@@ -3916,12 +3909,9 @@ rb_check_realpath_internal(VALUE basedir, VALUE path, enum rb_realpath_mode mode
if (!NIL_P(basedir)) {
FilePathValue(basedir);
- basedir = TO_OSPATH(rb_str_dup_frozen(basedir));
+ basedir = rb_str_dup_frozen(basedir);
}
- enc = rb_enc_get(unresolved_path);
- origenc = enc;
- unresolved_path = TO_OSPATH(unresolved_path);
RSTRING_GETMEM(unresolved_path, ptr, len);
path_names = skipprefixroot(ptr, ptr + len, rb_enc_get(unresolved_path));
if (ptr != path_names) {
@@ -3938,7 +3928,7 @@ rb_check_realpath_internal(VALUE basedir, VALUE path, enum rb_realpath_mode mode
}
}
- curdir = rb_dir_getwd_ospath();
+ curdir = rb_dir_getwd();
RSTRING_GETMEM(curdir, ptr, len);
curdir_names = skipprefixroot(ptr, ptr + len, rb_enc_get(curdir));
resolved = rb_str_subseq(curdir, 0, curdir_names - ptr);
@@ -3946,6 +3936,7 @@ rb_check_realpath_internal(VALUE basedir, VALUE path, enum rb_realpath_mode mode
root_found:
RSTRING_GETMEM(resolved, prefixptr, prefixlen);
pend = prefixptr + prefixlen;
+ enc = rb_enc_get(resolved);
ptr = chompdirsep(prefixptr, pend, enc);
if (ptr < pend) {
prefixlen = ++ptr - prefixptr;
@@ -3960,6 +3951,7 @@ rb_check_realpath_internal(VALUE basedir, VALUE path, enum rb_realpath_mode mode
}
#endif
+ origenc = enc;
switch (rb_enc_to_index(enc)) {
case ENCINDEX_ASCII:
case ENCINDEX_US_ASCII:
@@ -3978,14 +3970,8 @@ rb_check_realpath_internal(VALUE basedir, VALUE path, enum rb_realpath_mode mode
if (realpath_rec(&prefixlen, &resolved, path_names, loopcheck, mode, 1))
return Qnil;
- if (origenc != rb_enc_get(resolved)) {
- if (rb_enc_str_asciionly_p(resolved)) {
- rb_enc_associate(resolved, origenc);
- }
- else {
- resolved = rb_str_conv_enc(resolved, NULL, origenc);
- }
- }
+ if (origenc != enc && rb_enc_str_asciionly_p(resolved))
+ rb_enc_associate(resolved, origenc);
OBJ_TAINT(resolved);
return resolved;