This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Flush buffer before duplicating file descriptor.
authorMark-Jason Dominus <mjd@plover.com>
Wed, 11 Aug 1999 15:56:09 +0000 (11:56 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Wed, 11 Aug 1999 22:17:55 +0000 (22:17 +0000)
To: Graham Barr <gbarr@pobox.com>
cc: Vicki Brown <vlb@cfcl.com>, perl5-porters@perl.org, mjd@plover.com
Subject: Re: [ID 19990811.002] can't dup DATA? (PATCH (5.005_57))
Date: Wed, 11 Aug 1999 15:56:09 -0400
Message-ID: <19990811195610.5933.qmail@plover.com>

From: Mark-Jason Dominus <mjd@plover.com>
To: perl5-porters@perl.org
Subject: Re: [ID 19990811.002] can't dup DATA? (PATCH (5.005_57))
Date: Wed, 11 Aug 1999 16:05:46 -0400
Message-ID: <19990811200546.6165.qmail@plover.com>

p4raw-id: //depot/cfgperl@3960

doio.c
pod/perldelta.pod

diff --git a/doio.c b/doio.c
index cc34733..a953d54 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -282,7 +282,10 @@ Perl_do_open9(pTHX_ GV *gv, register char *name, I32 len, int as_raw,
                            goto say_false;
                        }
                        if (IoIFP(thatio)) {
-                           fd = PerlIO_fileno(IoIFP(thatio));
+                           PerlIO *fp = IoIFP(thatio);
+                               /* Flush stdio buffer before dup */
+                           PerlIO_seek(fp, 0, SEEK_CUR);
+                           fd = PerlIO_fileno(fp);
                            if (IoTYPE(thatio) == 's')
                                IoTYPE(io) = 's';
                        }
index 029d315..28a786e 100644 (file)
@@ -301,6 +301,14 @@ are compile time errors.  Attempting to read from filehandles that
 were opened only for writing will now produce warnings (just as
 writing to read-only filehandles does).
 
+=head2 Buffered data discarded from input filehandle when dup'ed.
+
+C<open(NEW, "E<lt>&OLD")> now discards any data that was previously
+read and buffered in C<OLD>.  The next read operation on C<NEW> will
+return the same data as the corresponding operation on C<OLD>.
+Formerly, it would have returned the data from the start of the
+following disk block instead.
+
 =head1 Supported Platforms
 
 =over 4