Skip to content

Commit 38b810a

Browse files
committed
IO::Handle: clear the error on both input and output streams
Similarly to GH Perl#6799 clearerr() only cleared the error status of the input stream, so clear both.
1 parent e32b6c7 commit 38b810a

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

dist/IO/IO.xs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,21 @@ ferror(handle)
410410

411411
int
412412
clearerr(handle)
413-
InputStream handle
413+
SV * handle
414+
PREINIT:
415+
IO *io = sv_2io(handle);
416+
InputStream in = IoIFP(io);
417+
OutputStream out = IoOFP(io);
414418
CODE:
415419
if (handle) {
416420
#ifdef PerlIO
417-
PerlIO_clearerr(handle);
421+
PerlIO_clearerr(in);
422+
if (in != out)
423+
PerlIO_clearerr(out);
418424
#else
419-
clearerr(handle);
425+
clearerr(in);
426+
if (in != out)
427+
clearerr(out);
420428
#endif
421429
RETVAL = 0;
422430
}

dist/IO/t/io_xs.t

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ BEGIN {
1111
}
1212
}
1313

14-
use Test::More tests => 7;
14+
use Test::More tests => 8;
1515
use IO::File;
1616
use IO::Seekable;
1717

@@ -58,12 +58,14 @@ SKIP: {
5858
# This isn't really a Linux/BSD specific test, but /dev/full is (I
5959
# hope) reasonably well defined on these. Patches welcome if your platform
6060
# also supports it (or something like it)
61-
skip "no /dev/full or not a /dev/full platform", 2
61+
skip "no /dev/full or not a /dev/full platform", 3
6262
unless $^O =~ /^(linux|netbsd|freebsd)$/ && -c "/dev/full";
6363
open my $fh, ">", "/dev/full"
64-
or skip "Could not open /dev/full: $!", 2;
64+
or skip "Could not open /dev/full: $!", 3;
6565
$fh->print("a" x 1024);
6666
ok(!$fh->flush, "should fail to flush");
6767
ok($fh->error, "stream should be in error");
68+
$fh->clearerr;
69+
ok(!$fh->error, "check clearerr removed the error");
6870
close $fh; # silently ignore the error
6971
}

0 commit comments

Comments
 (0)