summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-08-02 05:15:02 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-08-02 05:15:02 +0000
commite60d35e30292bf85719dc4c89f6fc3ef8845751b (patch)
tree402ee648119c7da74133b1e0acb7bb224566798b /win32
parenta2b8925a94a672235ca6a16e584bf09026a957ab (diff)
win32/file.c: use allocv buffer and API
* win32/file.c (rb_freopen): convert path name into allocv buffer and get rid of conversion failure in the case non-terminated string. [ruby-core:69780] [Bug #11320] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/file.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/win32/file.c b/win32/file.c
index 5353c546e2..7de58d48c9 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -729,13 +729,18 @@ int
rb_freopen(VALUE fname, const char *mode, FILE *file)
{
WCHAR *wname, wmode[4];
+ VALUE wtmp;
+ char *name;
long len;
int e = 0, n = MultiByteToWideChar(CP_ACP, 0, mode, -1, NULL, 0);
if (n > numberof(wmode)) return EINVAL;
MultiByteToWideChar(CP_ACP, 0, mode, -1, wmode, numberof(wmode));
- wname = rb_w32_mbstr_to_wstr(CP_UTF8, RSTRING_PTR(fname),
- rb_long2int(RSTRING_LEN(fname)) + 1, &len);
- wname[len - 1] = L'\0';
+ RSTRING_GETMEM(fname, name, len);
+ n = rb_long2int(len);
+ len = MultiByteToWideChar(CP_UTF8, 0, name, n, NULL, 0);
+ wname = ALLOCV_N(WCHAR, wtmp, len + 1);
+ len = MultiByteToWideChar(CP_UTF8, 0, name, n, wname, len);
+ wname[len] = L'\0';
RB_GC_GUARD(fname);
#if RUBY_MSVCRT_VERSION < 80 && !defined(HAVE__WFREOPEN_S)
e = _wfreopen(wname, wmode, file) ? 0 : errno;
@@ -745,7 +750,7 @@ rb_freopen(VALUE fname, const char *mode, FILE *file)
e = _wfreopen_s(&newfp, wname, wmode, file);
}
#endif
- free(wname);
+ ALLOCV_END(wtmp);
return e;
}