# New Ticket Created by Leon Timmermans # Please include the string: [perl #82802] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=82802 > fileno is documented to return undef on error. It currently does so if the file isn't opened, but when the fileno method of PerlIO returns -1 it returns that value verbatim, instead of turning it into an undef. This patch fixes that. It breaks some assumptions of Scalar::Util's openhandle, a patch to its author will be sent at the same time. --- pp_sys.c | 7 ++++++- t/io/perlio.t | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pp_sys.c b/pp_sys.c index 73a5c8a..0205390 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -697,6 +697,7 @@ PP(pp_fileno) IO *io; PerlIO *fp; const MAGIC *mg; + IV ret; if (MAXARG < 1) RETPUSHUNDEF; @@ -718,7 +719,11 @@ PP(pp_fileno) RETPUSHUNDEF; } - PUSHi(PerlIO_fileno(fp)); + ret = PerlIO_fileno(fp); + if (ret >= 0) + PUSHi(ret); + else + PUSHs(&PL_sv_undef); RETURN; } diff --git a/t/io/perlio.t b/t/io/perlio.t index 8b1cff3..28924ed 100644 --- a/t/io/perlio.t +++ b/t/io/perlio.t @@ -139,7 +139,7 @@ SKIP: { } my $var; ok( open(my $x,"+<",\$var), 'magic in-memory file via 3 arg open with \\$var'); - ok( defined fileno($x), ' fileno' ); + ok( !defined fileno($x), ' fileno' ); select $x; ok( (print "ok\n"), ' print' ); -- 1.7.1Thread Next