aboutsummaryrefslogtreecommitdiffstats
path: root/dir.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-05 17:28:07 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-05 17:28:07 +0000
commitc52955454887fff551f7efcfa44f558f16a85269 (patch)
treea0381b83fa164ba01f2d7dd74244a922618200d1 /dir.c
parent5dac166fb2c943a057363c599d7e0d5303d4f62d (diff)
downloadruby-c52955454887fff551f7efcfa44f558f16a85269.tar.gz
* dir.c (replace_real_basename): shouldn't create Ruby object before
the object system is loaded. [ruby-core:68430] [Bug #10941] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/dir.c b/dir.c
index 4e5744c4e2..9a6d977dca 100644
--- a/dir.c
+++ b/dir.c
@@ -1488,12 +1488,22 @@ replace_real_basename(char *path, long base, rb_encoding *enc, int norm_p)
free(wplain);
if (h == INVALID_HANDLE_VALUE) return path;
FindClose(h);
- tmp = rb_w32_conv_from_wchar(fd.cFileName, enc);
- wlen = RSTRING_LEN(tmp);
- path = GLOB_REALLOC(path, base + wlen + 1);
- memcpy(path + base, RSTRING_PTR(tmp), wlen);
+ if (tmp) {
+ tmp = rb_w32_conv_from_wchar(fd.cFileName, enc);
+ wlen = RSTRING_LEN(tmp);
+ path = GLOB_REALLOC(path, base + wlen + 1);
+ memcpy(path + base, RSTRING_PTR(tmp), wlen);
+ rb_str_resize(tmp, 0);
+ }
+ else {
+ char *utf8filename;
+ wlen = WideCharToMultiByte(CP_UTF8, 0, fd.cFileName, -1, NULL, 0, NULL, NULL);
+ utf8filename = GLOB_REALLOC(0, wlen);
+ WideCharToMultiByte(CP_UTF8, 0, fd.cFileName, -1, utf8filename, wlen, NULL, NULL);
+ memcpy(path + base, utf8filename, wlen);
+ GLOB_FREE(utf8filename);
+ }
path[base + wlen] = 0;
- rb_str_resize(tmp, 0);
return path;
}
#elif USE_NAME_ON_FS == 1