From: Simon Strandgaard Date: 2004-05-21T16:00:29+09:00 Subject: Re: [rcr] make File#dup intuitive nobu.nokada@softhome.net wrote: > At Fri, 21 May 2004 15:38:00 +0900, > Simon Strandgaard wrote in [ruby-talk:100979]: > > I just applied your patch.. it seems as the position now > > gets zeroed. > > Sorry, too stupid. I have sligthly adjusted your original patch, so it now works server> diff -U2 bak/io.c io.c --- bak/io.c Fri May 21 08:51:22 2004 +++ io.c Fri May 21 08:46:00 2004 @@ -3295,4 +3295,5 @@ int fd; char *mode; + off_t pos1, pos2; io = rb_io_get_io(io); @@ -3303,12 +3304,11 @@ if (orig->f2) { io_fflush(orig->f2, orig); - fseeko(orig->f, 0L, SEEK_CUR); + pos2 = fseeko(orig->f2, 0L, SEEK_CUR); } else if (orig->mode & FMODE_WRITABLE) { io_fflush(orig->f, orig); } - else { - fseeko(orig->f, 0L, SEEK_CUR); - } + pos1 = io_tell(orig); + fseeko(orig->f, 0L, SEEK_CUR); /* copy OpenFile structure */ @@ -3332,4 +3332,5 @@ fd = ruby_dup(fileno(orig->f)); fptr->f = rb_fdopen(fd, mode); + fseeko(fptr->f, pos1, SEEK_SET); if (orig->f2) { if (fileno(orig->f) != fileno(orig->f2)) { @@ -3337,4 +3338,5 @@ } fptr->f2 = rb_fdopen(fd, "w"); + fseeko(fptr->f2, pos2, SEEK_SET); } if (fptr->mode & FMODE_BINMODE) { server> I will try your patch right away. Thanks -- Simon Strandgaard