Make the return value of close() depend not only on the success of the
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Thu, 10 Mar 2005 17:42:54 +0000 (17:42 +0000)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Thu, 10 Mar 2005 17:42:54 +0000 (17:42 +0000)
close itself, but also on whether the output stream had a previous
error. From Jim Meyering <jim@meyering.net>, via Debian.

p4raw-id: //depot/perl@24022

doio.c

diff --git a/doio.c b/doio.c
index 6fe0c85..df7f656 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -1059,11 +1059,14 @@ Perl_io_close(pTHX_ IO *io, bool not_implicit)
            retval = TRUE;
        else {
            if (IoOFP(io) && IoOFP(io) != IoIFP(io)) {          /* a socket */
-               retval = (PerlIO_close(IoOFP(io)) != EOF);
+               bool prev_err = PerlIO_error(IoOFP(io));
+               retval = (PerlIO_close(IoOFP(io)) != EOF && !prev_err);
                PerlIO_close(IoIFP(io));        /* clear stdio, fd already closed */
            }
-           else
-               retval = (PerlIO_close(IoIFP(io)) != EOF);
+           else {
+               bool prev_err = PerlIO_error(IoIFP(io));
+               retval = (PerlIO_close(IoIFP(io)) != EOF && !prev_err);
+           }
        }
        IoOFP(io) = IoIFP(io) = Nullfp;
     }