diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-06-30 08:28:28 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-06-30 08:28:28 +0000 |
commit | 93446fedd3ae3efcccdeede1a5af1ec7e8b6d1cd (patch) | |
tree | d539771ef9221c64d3f81661aee7e4bf347e7891 /win32 | |
parent | c810ab8ff57371bf65b0bb20f268871398c8f7e8 (diff) |
io.c: reopen OS encoding path
* io.c (rb_io_reopen): freopen(3) with OS encoding path.
[ruby-core:69780] [Bug #11320]
* win32/file.c (rb_freopen): wrapper of wchar version freopen(3).
use _wfreopen_s() if available.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51069 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r-- | win32/file.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/win32/file.c b/win32/file.c index 4a31fe37eb..799810a4ef 100644 --- a/win32/file.c +++ b/win32/file.c @@ -721,6 +721,28 @@ rb_file_load_ok(const char *path) return ret; } +int +rb_freopen(VALUE fname, const char *mode, FILE *file) +{ + WCHAR *wname, wmode[4]; + 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)), NULL); + RB_GC_GUARD(fname); +#if RUBY_MSVCRT_VERSION < 80 && !defined(HAVE__WFREOPEN_S) + e = _wfreopen(wname, wmode, file) ? 0 : errno; +#else + { + FILE *newfp = 0; + e = _wfreopen_s(&newfp, wname, wmode, file); + } +#endif + xfree(wname); + return e; +} + void Init_w32_codepage(void) { |