This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Flush buffer before duplicating file descriptor.
[perl5.git] / doio.c
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';
                        }