diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-05-09 08:12:52 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-05-09 08:12:52 +0000 |
commit | 4870c89f777c8ae4403e9127a4df9f9c06cb5995 (patch) | |
tree | 6716582f7f160e0ba08bafce00fe9a74817a10fe /io.c | |
parent | 13230a3417e37edaf5cdfaedafde5b7e19a34e6e (diff) | |
download | ruby-4870c89f777c8ae4403e9127a4df9f9c06cb5995.tar.gz |
* io.c (rb_io_reopen): It should be possible to reopen closed IO.
[ruby-talk:70941]
* io.c (rb_io_reopen): inherit original file mode unless specified.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 41 |
1 files changed, 39 insertions, 2 deletions
@@ -1614,6 +1614,39 @@ rb_io_binmode(io) return io; } +char* +rb_io_flags_mode(flags, mode) + int flags; + char *mode; +{ + char *p = mode; + + switch (flags & FMODE_READWRITE) { + case FMODE_READABLE: + *p++ = 'r'; + break; + case FMODE_WRITABLE: + *p++ = 'w'; + break; + case FMODE_READWRITE: + *p++ = 'r'; + *p++ = '+'; + break; + } + *p++ = '\0'; +#ifdef O_BINARY + if (flags & FMODE_BINMODE) { + if (mode[1] == '+') { + mode[1] = 'b'; mode[2] = '+'; mode[3] = '\0'; + } + else { + mode[1] = 'b'; mode[2] = '\0'; + } + } +#endif + return mode; +} + int rb_io_mode_flags(mode) const char *mode; @@ -2387,14 +2420,18 @@ rb_io_reopen(argc, argv, file) } SafeStringValue(fname); + + rb_io_taint_check(file); + fptr = RFILE(file)->fptr; + if (!NIL_P(nmode)) { mode = StringValuePtr(nmode); } else { - mode = "r"; + mode = ALLOCA_N(char, 4); + rb_io_flags_mode(fptr->mode, mode); } - GetOpenFile(file, fptr); if (fptr->path) { free(fptr->path); fptr->path = 0; |