diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | io.c | 41 |
2 files changed, 46 insertions, 2 deletions
@@ -1,3 +1,10 @@ +Fri May 9 16:38:30 2003 Yukihiro Matsumoto <matz@ruby-lang.org> + + * 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. + Thu May 8 18:44:09 2003 Yukihiro Matsumoto <matz@ruby-lang.org> * gc.c (rb_gc): check odd alignment stack on m68k machines. @@ -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; |