Automatically flush on C< $| = 1 >
Chip Salzenberg [Fri, 21 Mar 1997 19:42:31 +0000 (07:42 +1200)]
mg.c

diff --git a/mg.c b/mg.c
index c3e6153..5b25c40 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -1374,9 +1374,18 @@ MAGIC* mg;
        IoPAGE(GvIOp(defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
        break;
     case '|':
-       IoFLAGS(GvIOp(defoutgv)) &= ~IOf_FLUSH;
-       if ((SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) != 0) {
-           IoFLAGS(GvIOp(defoutgv)) |= IOf_FLUSH;
+       {
+           IO *io = GvIOp(defoutgv);
+           if ((SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) == 0)
+               IoFLAGS(io) &= ~IOf_FLUSH;
+           else {
+               if (!(IoFLAGS(io) & IOf_FLUSH)) {
+                   PerlIO *ofp = IoOFP(io);
+                   if (ofp)
+                       (void)PerlIO_flush(ofp);
+                   IoFLAGS(io) |= IOf_FLUSH;
+               }
+           }
        }
        break;
     case '*':