aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-30 08:28:28 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-30 08:28:28 +0000
commit93446fedd3ae3efcccdeede1a5af1ec7e8b6d1cd (patch)
treed539771ef9221c64d3f81661aee7e4bf347e7891 /io.c
parentc810ab8ff57371bf65b0bb20f268871398c8f7e8 (diff)
downloadruby-93446fedd3ae3efcccdeede1a5af1ec7e8b6d1cd.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.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/io.c b/io.c
index 8358c74ff9..40d8920081 100644
--- a/io.c
+++ b/io.c
@@ -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