This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
report an error and fail if we can't flush stdout
authorTony Cook <tony@develop-help.com>
Wed, 4 Nov 2015 05:52:37 +0000 (16:52 +1100)
committerRicardo Signes <rjbs@cpan.org>
Thu, 17 Mar 2016 23:52:56 +0000 (19:52 -0400)
perl.c

diff --git a/perl.c b/perl.c
index 5c71fd0..94c810e 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -585,6 +585,19 @@ perl_destruct(pTHXx)
     assert(PL_scopestack_ix == 0);
 
     /* Need to flush since END blocks can produce output */
+    /* flush stdout separately, since we can identify it */
+#ifdef USE_PERLIO
+    {
+        PerlIO *stdo = PerlIO_stdout();
+        if (*stdo && PerlIO_flush(stdo)) {
+            PerlIO_restore_errno(stdo);
+            PerlIO_printf(PerlIO_stderr(), "Unable to flush stdout: %s",
+                          Strerror(errno));
+            if (!STATUS_UNIX)
+                STATUS_ALL_FAILURE;
+        }
+    }
+#endif
     my_fflush_all();
 
 #ifdef PERL_TRACE_OPS