Change 18475 by jhi@lyta on 2003/01/13 02:42:47

        Integrate from perlio:
        [ 18471]
        Fix #18711 and add test for it (and indeed tell on write
        handles at all !
        
        (#18711 Serious bug of tell() in perl)

Affected files ...

... //depot/perl/perlio.c#196 integrate
... //depot/perl/t/io/tell.t#15 integrate

Differences ...

==== //depot/perl/perlio.c#196 (text) ====
Index: perl/perlio.c
--- perl/perlio.c#195~18474~    Sun Jan 12 18:41:04 2003
+++ perl/perlio.c       Sun Jan 12 18:42:47 2003
@@ -3427,6 +3427,11 @@
        PerlIO_get_base(f);
     if (!(PerlIOBase(f)->flags & PERLIO_F_CANWRITE))
        return 0;
+    if (PerlIOBase(f)->flags & PERLIO_F_RDBUF) {
+       if (PerlIO_flush(f) != 0) {
+           return 0;
+       }
+    }  
     while (count > 0) {
        SSize_t avail = b->bufsiz - (b->ptr - b->buf);
        if ((SSize_t) count < avail)
@@ -3485,6 +3490,19 @@
      * b->posn is file position where b->buf was read, or will be written
      */
     Off_t posn = b->posn;
+    if ((PerlIOBase(f)->flags & PERLIO_F_APPEND) && 
+        (PerlIOBase(f)->flags & PERLIO_F_WRBUF)) {
+#if 1
+       /* As O_APPEND files are normally shared in some sense it is better
+          to flush :
+        */     
+       PerlIO_flush(f);
+#else  
+        /* when file is NOT shared then this is sufficient */ 
+       PerlIO_seek(PerlIONext(f),0, SEEK_END);
+#endif
+       posn = b->posn = PerlIO_tell(PerlIONext(f));
+    }
     if (b->buf) {
        /*
         * If buffer is valid adjust position by amount in buffer

==== //depot/perl/t/io/tell.t#15 (xtext) ====
Index: perl/t/io/tell.t
--- perl/t/io/tell.t#14~11730~  Wed Aug 22 14:35:30 2001
+++ perl/t/io/tell.t    Sun Jan 12 18:42:47 2003
@@ -7,7 +7,7 @@
     @INC = '../lib';
 }
 
-print "1..23\n";
+print "1..27\n";
 
 $TST = 'tst';
 
@@ -96,4 +96,48 @@
 # ftell(STDIN) (or any std streams) is undefined, it can return -1 or
 # something else.  ftell() on pipes, fifos, and sockets is defined to
 # return -1.
+
+my $written = "tell_write.txt";
+
+END { unlink($written) }
+
+close($tst);
+open($tst,">$written")  || die "Cannot open $written:$!";
+binmode $TST if $Is_Dosish;
+
+if (tell($tst) == 0) { print "ok 24\n"; } else { print "not ok 24\n"; }
+
+print $tst "fred\n";
+
+if (tell($tst) == 5) { print "ok 25\n"; } else { print "not ok 25\n"; }
+
+print $tst "more\n";
+
+if (tell($tst) == 10) { print "ok 26\n"; } else { print "not ok 26\n"; }
+
+close($tst);
+
+open($tst,"+>>$written")  || die "Cannot open $written:$!";
+binmode $TST if $Is_Dosish;
+
+if (0) 
+{
+ # :stdio does not pass these so ignore them for now 
+
+if (tell($tst) == 0) { print "ok 27\n"; } else { print "not ok 27\n"; }
+
+$line = <$tst>;
+
+if ($line eq "fred\n") { print "ok 29\n"; } else { print "not ok 29\n"; }
+
+if (tell($tst) == 5) { print "ok 30\n"; } else { print "not ok 30\n"; }
+
+}
+
+print $tst "xxxx\n";
+
+if (tell($tst) == 15) { print "ok 27\n"; } else { print "not ok 27\n"; }
+
+close($tst);
+
 
End of Patch.

Reply via email to