This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
IO::Handle: clear the error on both input and output streams
authorTony Cook <tony@develop-help.com>
Tue, 12 May 2020 00:59:08 +0000 (10:59 +1000)
committerKarl Williamson <khw@cpan.org>
Thu, 30 Jul 2020 21:29:22 +0000 (15:29 -0600)
Similarly to GH #6799 clearerr() only cleared the error status
of the input stream, so clear both.

dist/IO/IO.xs
dist/IO/t/io_xs.t

index 99d523d..9158106 100644 (file)
@@ -410,13 +410,21 @@ ferror(handle)
 
 int
 clearerr(handle)
-       InputStream     handle
+       SV *    handle
+    PREINIT:
+        IO *io = sv_2io(handle);
+        InputStream in = IoIFP(io);
+        OutputStream out = IoOFP(io);
     CODE:
        if (handle) {
 #ifdef PerlIO
-           PerlIO_clearerr(handle);
+           PerlIO_clearerr(in);
+            if (in != out)
+                PerlIO_clearerr(out);
 #else
-           clearerr(handle);
+           clearerr(in);
+            if (in != out)
+                clearerr(out);
 #endif
            RETVAL = 0;
        }
index f890e92..a8833b0 100644 (file)
@@ -11,7 +11,7 @@ BEGIN {
     }
 }
 
-use Test::More tests => 7;
+use Test::More tests => 8;
 use IO::File;
 use IO::Seekable;
 
@@ -58,12 +58,14 @@ SKIP: {
     # This isn't really a Linux/BSD specific test, but /dev/full is (I
     # hope) reasonably well defined on these.  Patches welcome if your platform
     # also supports it (or something like it)
-    skip "no /dev/full or not a /dev/full platform", 2
+    skip "no /dev/full or not a /dev/full platform", 3
       unless $^O =~ /^(linux|netbsd|freebsd)$/ && -c "/dev/full";
     open my $fh, ">", "/dev/full"
-      or skip "Could not open /dev/full: $!", 2;
+      or skip "Could not open /dev/full: $!", 3;
     $fh->print("a" x 1024);
     ok(!$fh->flush, "should fail to flush");
     ok($fh->error, "stream should be in error");
+    $fh->clearerr;
+    ok(!$fh->error, "check clearerr removed the error");
     close $fh; # silently ignore the error
 }