mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
13230a3417
commit
4870c89f77
2 changed files with 46 additions and 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.
|
||||
|
|
41
io.c
41
io.c
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue