summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-23 00:38:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-23 00:38:39 +0000
commitb258364f306f59b212dbc492596cedb55e4bb44d (patch)
tree683b63f7b9182d602c6b2ac2511a3fc371810e56 /io.c
parent8bb2f7d56ab6cb752277745c38846d19cfa8a1a6 (diff)
* io.c (io_reopen): restore exact mode. fixed: [ruby-core:04003]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/io.c b/io.c
index 370765a085..0604b6e0ef 100644
--- a/io.c
+++ b/io.c
@@ -3185,10 +3185,11 @@ io_reopen(io, nfile)
}
else {
FILE *f2 = fptr->f2;
+ int m = fptr->mode;
fclose(fptr->f);
fptr->f = f2;
fptr->f2 = NULL;
- fptr->mode &= ~FMODE_READABLE;
+ fptr->mode &= (m & FMODE_READABLE) ? ~FMODE_READABLE : ~FMODE_WRITABLE;
if (dup2(fd2, fd) < 0)
rb_sys_fail(orig->path);
if (f2) {
@@ -3198,7 +3199,7 @@ io_reopen(io, nfile)
else {
fptr->f = rb_fdopen(fd, mode);
}
- fptr->mode |= FMODE_READABLE;
+ fptr->mode = m;
}
rb_thread_fd_close(fd);
if ((orig->mode & FMODE_READABLE) && pos >= 0) {