From: Stepan Kasal Date: Wed, 3 Jun 2009 10:03:55 +0000 (+0200) Subject: fix RT 39060, errno incorrectly set in perlio X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d7dfc388e04f41b8a0f5d8ef6e15ab3b79f483c8;p=p5sagit%2Fp5-mst-13.2.git fix RT 39060, errno incorrectly set in perlio --- diff --git a/MANIFEST b/MANIFEST index cc17868..c7e388e 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3907,6 +3907,7 @@ t/io/binmode.t See if binmode() works t/io/crlf.t See if :crlf works t/io/crlf_through.t See if pipe passes data intact with :crlf t/io/dup.t See if >& works right +t/io/errno.t See if $! is correctly set t/io/fflush.t See if auto-flush on fork/exec/system/qx works t/io/fs.t See if directory manipulations work t/io/inplace.t See if inplace editing works diff --git a/perlio.c b/perlio.c index 0a086a8..e92a32a 100644 --- a/perlio.c +++ b/perlio.c @@ -1784,12 +1784,14 @@ PerlIO_has_base(PerlIO *f) int PerlIO_fast_gets(PerlIO *f) { - if (PerlIOValid(f) && (PerlIOBase(f)->flags & PERLIO_F_FASTGETS)) { - const PerlIO_funcs * const tab = PerlIOBase(f)->tab; + if (PerlIOValid(f)) { + if (PerlIOBase(f)->flags & PERLIO_F_FASTGETS) { + const PerlIO_funcs * const tab = PerlIOBase(f)->tab; - if (tab) - return (tab->Set_ptrcnt != NULL); - SETERRNO(EINVAL, LIB_INVARG); + if (tab) + return (tab->Set_ptrcnt != NULL); + SETERRNO(EINVAL, LIB_INVARG); + } } else SETERRNO(EBADF, SS_IVCHAN); diff --git a/t/io/errno.t b/t/io/errno.t new file mode 100644 index 0000000..b55e3db --- /dev/null +++ b/t/io/errno.t @@ -0,0 +1,26 @@ +#!./perl +# vim: ts=4 sts=4 sw=4: + +# $! may not be set if EOF was reached without any error. +# http://rt.perl.org/rt3/Ticket/Display.html?id=39060 + +use strict; +require './test.pl'; + +plan( tests => 16 ); + +my $test_prog = 'while(<>){print}; print $!'; + +for my $perlio ('perlio', 'stdio') { + $ENV{PERLIO} = $perlio; + for my $test_in ("test\n", "test") { + my $test_in_esc = $test_in; + $test_in_esc =~ s/\n/\\n/g; + for my $rs_code ('', '$/=undef', '$/=\2', '$/=\1024') { + is( runperl( prog => "$rs_code; $test_prog", + stdin => $test_in, stderr => 1), + $test_in, + "Wrong errno, PERLIO=$ENV{PERLIO} stdin='$test_in_esc'"); + } + } +}