summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-21 03:22:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-21 03:22:48 +0000
commit63699fc66a2168896116b0d5b9c2074156992dc6 (patch)
tree02e742e98cf39e9c16cf640bf143dc7f0dc1475e /io.c
parent519aed5fabb945ec0cba25f0f0fd6934819983f2 (diff)
* io.c (io_reopen): keep duplex pipe in correct mode for exception
safeness. fixed: [ruby-dev:25152] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7622 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/io.c b/io.c
index 7e4de96..2a23129 100644
--- a/io.c
+++ b/io.c
@@ -3180,11 +3180,21 @@ io_reopen(io, nfile)
rb_sys_fail(orig->path);
}
else {
+ FILE *f2 = fptr->f2;
fclose(fptr->f);
- fptr->f = NULL;
+ fptr->f = f2;
+ fptr->f2 = NULL;
+ fptr->mode &= ~FMODE_READABLE;
if (dup2(fd2, fd) < 0)
rb_sys_fail(orig->path);
- fptr->f = rb_fdopen(fd, mode);
+ if (f2) {
+ fptr->f = rb_fdopen(fd, "r");
+ fptr->f2 = f2;
+ fptr->mode |= FMODE_READABLE;
+ }
+ else {
+ fptr->f = rb_fdopen(fd, mode);
+ }
}
rb_thread_fd_close(fd);
if ((orig->mode & FMODE_READABLE) && pos >= 0) {