summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-06-14 08:08:50 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-06-14 08:08:50 +0000
commit1199a7d3d6399d44662b9a8bea5f359d1fdd40c2 (patch)
tree41f75742290a2ab9c156eccf4293949fb4c7e0a4 /io.c
parent8c4f656b6cbc088d215b0fd083611e7e6b6040a5 (diff)
2000-06-14-2
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/io.c b/io.c
index 0d604a9fe3..a2dca1a4a0 100644
--- a/io.c
+++ b/io.c
@@ -1755,6 +1755,7 @@ io_reopen(io, nfile)
OpenFile *fptr, *orig;
char *mode;
int fd;
+ long pos;
nfile = rb_io_get_io(nfile);
if (rb_safe_level() >= 4 && (!OBJ_TAINTED(io) || !OBJ_TAINTED(nfile))) {
@@ -1764,6 +1765,9 @@ io_reopen(io, nfile)
GetOpenFile(nfile, orig);
if (fptr == orig) return io;
+ if (orig->mode & FMODE_READABLE) {
+ pos = ftell(orig->f);
+ }
if (orig->f2) {
if (fflush(orig->f2) == EOF) rb_sys_fail(orig->path);
}
@@ -1793,6 +1797,9 @@ io_reopen(io, nfile)
if (dup2(fileno(orig->f), fd) < 0)
rb_sys_fail(orig->path);
fptr->f = rb_fdopen(fd, mode);
+ if (orig->mode & FMODE_READABLE && pos >= 0) {
+ fseek(fptr->f, pos, SEEK_SET);
+ }
}
if (fptr->f2) {