This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Implement flush of linebuffered streams on read of a tty.
authorNick Ing-Simmons <nik@tiuk.ti.com>
Mon, 26 Mar 2001 17:32:06 +0000 (17:32 +0000)
committerNick Ing-Simmons <nik@tiuk.ti.com>
Mon, 26 Mar 2001 17:32:06 +0000 (17:32 +0000)
p4raw-id: //depot/perlio@9361

perlio.c
perliol.h

index d33c0cb..50e3be1 100644 (file)
--- a/perlio.c
+++ b/perlio.c
@@ -1140,6 +1140,25 @@ PerlIO_flush(PerlIO *f)
   }
 }
 
+void
+PerlIOBase_flush_linebuf()
+{
+ PerlIO **table = &_perlio;
+ PerlIO *f;
+ while ((f = *table))
+  {
+   int i;
+   table = (PerlIO **)(f++);
+   for (i=1; i < PERLIO_TABLE_SIZE; i++)
+    {
+     if (*f && (PerlIOBase(f)->flags & (PERLIO_F_LINEBUF|PERLIO_F_CANWRITE))
+                == (PERLIO_F_LINEBUF|PERLIO_F_CANWRITE))
+      PerlIO_flush(f);
+     f++;
+    }
+  }
+}
+
 #undef PerlIO_fill
 int
 PerlIO_fill(PerlIO *f)
@@ -2331,7 +2350,7 @@ PerlIOBuf_pushed(PerlIO *f, const char *mode, SV *arg)
  dTHX;
  if (fd >= 0 && PerlLIO_isatty(fd))
   {
-   PerlIOBase(f)->flags |= PERLIO_F_LINEBUF;
+   PerlIOBase(f)->flags |= PERLIO_F_LINEBUF|PERLIO_F_TTY;
   }
  posn = PerlIO_tell(PerlIONext(f));
  if (posn != (Off_t) -1)
@@ -2450,6 +2469,8 @@ PerlIOBuf_fill(PerlIO *f)
   */
  if (PerlIO_flush(f) != 0)
   return -1;
+ if (PerlIOBase(f)->flags & PERLIO_F_TTY)
+  PerlIOBase_flush_linebuf();
 
  if (!b->buf)
   PerlIO_get_base(f); /* allocate via vtable */
index d4604e2..de87547 100644 (file)
--- a/perliol.h
+++ b/perliol.h
@@ -74,6 +74,7 @@ struct _PerlIO
 #define PERLIO_F_TEMP          0x00100000
 #define PERLIO_F_OPEN          0x00200000
 #define PERLIO_F_FASTGETS      0x00400000
+#define PERLIO_F_TTY           0x00800000
 
 #define PerlIOBase(f)      (*(f))
 #define PerlIOSelf(f,type) ((type *)PerlIOBase(f))
@@ -118,6 +119,7 @@ extern IV   PerlIOBase_flush     (PerlIO *f);
 extern IV      PerlIOBase_fill      (PerlIO *f);
 extern IV      PerlIOBase_close     (PerlIO *f);
 extern void    PerlIOBase_setlinebuf(PerlIO *f);
+extern void    PerlIOBase_flush_linebuf(void);
 
 extern IV      PerlIOBase_noop_ok   (PerlIO *f);
 extern IV      PerlIOBase_noop_fail (PerlIO *f);