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 | bb5093fe0c96529a90381e8d54969334d30f3d96 (patch) | |
tree | d539771ef9221c64d3f81661aee7e4bf347e7891 /io.c | |
parent | 2e9eba44406fe5f62e2f9752fff900818190beba (diff) | |
download | ruby-bb5093fe0c96529a90381e8d54969334d30f3d96.tar.gz |
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 'io.c')
-rw-r--r-- | io.c | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -6706,6 +6706,20 @@ io_reopen(VALUE io, VALUE nfile) return io; } +#ifdef _WIN32 +int rb_freopen(VALUE fname, const char *mode, FILE *fp); +#else +static int +rb_freopen(VALUE fname, const char *mode, FILE *fp) +{ + if (!freopen(RSTRING_PTR(fname), mode, fp)) { + RB_GC_GUARD(fname); + return errno; + } + return 0; +} +#endif + /* * call-seq: * ios.reopen(other_IO) -> ios @@ -6777,9 +6791,10 @@ rb_io_reopen(int argc, VALUE *argv, VALUE file) fptr->rbuf.off = fptr->rbuf.len = 0; if (fptr->stdio_file) { - if (freopen(RSTRING_PTR(fptr->pathv), rb_io_oflags_modestr(oflags), fptr->stdio_file) == 0) { - rb_sys_fail_path(fptr->pathv); - } + int e = rb_freopen(rb_str_encode_ospath(fptr->pathv), + rb_io_oflags_modestr(oflags), + fptr->stdio_file); + if (e) rb_syserr_fail_path(e, fptr->pathv); fptr->fd = fileno(fptr->stdio_file); rb_fd_fix_cloexec(fptr->fd); #ifdef USE_SETVBUF |