diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-09-28 01:40:56 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-09-28 01:40:56 +0000 |
commit | 4a3c049cd1a02f3a650cec165178b33d8bfb0bfd (patch) | |
tree | 8d81b0c7da0ef2e5dae63538757654ab95d1a598 /io.c | |
parent | 8940e3721010e8867242ecf72d23a647304581a1 (diff) | |
download | ruby-4a3c049cd1a02f3a650cec165178b33d8bfb0bfd.tar.gz |
io.c: IO#reopen int mode
* io.c (rb_io_reopen): accept File::Constants as well as mode string.
based on the patch by Glass_saga (Masaki Matsushita) in
[ruby-core:47694]. [Feature #7067]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -6365,7 +6365,17 @@ rb_io_reopen(int argc, VALUE *argv, VALUE file) } if (!NIL_P(nmode)) { - int fmode = rb_io_modestr_fmode(StringValueCStr(nmode)); + VALUE intmode = rb_check_to_int(nmode); + int fmode; + + if (!NIL_P(intmode)) { + oflags = NUM2INT(intmode); + fmode = rb_io_oflags_fmode(oflags); + } + else { + fmode = rb_io_modestr_fmode(StringValueCStr(nmode)); + } + if (IS_PREP_STDIO(fptr) && ((fptr->mode & FMODE_READWRITE) & (fmode & FMODE_READWRITE)) != (fptr->mode & FMODE_READWRITE)) { @@ -6375,7 +6385,9 @@ rb_io_reopen(int argc, VALUE *argv, VALUE file) rb_io_fmode_modestr(fmode)); } fptr->mode = fmode; - rb_io_mode_enc(fptr, StringValueCStr(nmode)); + if (NIL_P(intmode)) { + rb_io_mode_enc(fptr, StringValueCStr(nmode)); + } fptr->encs.ecflags = 0; fptr->encs.ecopts = Qnil; } |