158f261
From fc5f3468dcbee38eb202cfd552a5b8dbff990c7b Mon Sep 17 00:00:00 2001
158f261
From: Tony Cook <tony@develop-help.com>
158f261
Date: Tue, 12 May 2020 10:59:08 +1000
158f261
Subject: [PATCH 2/2] IO::Handle: clear the error on both input and output
158f261
 streams
158f261
MIME-Version: 1.0
158f261
Content-Type: text/plain; charset=UTF-8
158f261
Content-Transfer-Encoding: 8bit
158f261
158f261
Similarly to GH #6799 clearerr() only cleared the error status
158f261
of the input stream, so clear both.
158f261
158f261
Signed-off-by: Petr Písař <ppisar@redhat.com>
158f261
---
158f261
 dist/IO/IO.xs     | 14 +++++++++++---
158f261
 dist/IO/t/io_xs.t |  8 +++++---
158f261
 2 files changed, 16 insertions(+), 6 deletions(-)
158f261
158f261
diff --git a/dist/IO/IO.xs b/dist/IO/IO.xs
158f261
index 99d523d2c1..9158106416 100644
158f261
--- a/dist/IO/IO.xs
158f261
+++ b/dist/IO/IO.xs
158f261
@@ -410,13 +410,21 @@ ferror(handle)
158f261
 
158f261
 int
158f261
 clearerr(handle)
158f261
-	InputStream	handle
158f261
+	SV *	handle
158f261
+    PREINIT:
158f261
+        IO *io = sv_2io(handle);
158f261
+        InputStream in = IoIFP(io);
158f261
+        OutputStream out = IoOFP(io);
158f261
     CODE:
158f261
 	if (handle) {
158f261
 #ifdef PerlIO
158f261
-	    PerlIO_clearerr(handle);
158f261
+	    PerlIO_clearerr(in);
158f261
+            if (in != out)
158f261
+                PerlIO_clearerr(out);
158f261
 #else
158f261
-	    clearerr(handle);
158f261
+	    clearerr(in);
158f261
+            if (in != out)
158f261
+                clearerr(out);
158f261
 #endif
158f261
 	    RETVAL = 0;
158f261
 	}
158f261
diff --git a/dist/IO/t/io_xs.t b/dist/IO/t/io_xs.t
158f261
index f890e92558..a8833b0651 100644
158f261
--- a/dist/IO/t/io_xs.t
158f261
+++ b/dist/IO/t/io_xs.t
158f261
@@ -11,7 +11,7 @@ BEGIN {
158f261
     }
158f261
 }
158f261
 
158f261
-use Test::More tests => 7;
158f261
+use Test::More tests => 8;
158f261
 use IO::File;
158f261
 use IO::Seekable;
158f261
 
158f261
@@ -58,12 +58,14 @@ SKIP: {
158f261
     # This isn't really a Linux/BSD specific test, but /dev/full is (I
158f261
     # hope) reasonably well defined on these.  Patches welcome if your platform
158f261
     # also supports it (or something like it)
158f261
-    skip "no /dev/full or not a /dev/full platform", 2
158f261
+    skip "no /dev/full or not a /dev/full platform", 3
158f261
       unless $^O =~ /^(linux|netbsd|freebsd)$/ && -c "/dev/full";
158f261
     open my $fh, ">", "/dev/full"
158f261
-      or skip "Could not open /dev/full: $!", 2;
158f261
+      or skip "Could not open /dev/full: $!", 3;
158f261
     $fh->print("a" x 1024);
158f261
     ok(!$fh->flush, "should fail to flush");
158f261
     ok($fh->error, "stream should be in error");
158f261
+    $fh->clearerr;
158f261
+    ok(!$fh->error, "check clearerr removed the error");
158f261
     close $fh; # silently ignore the error
158f261
 }
158f261
-- 
158f261
2.25.4
158f261