diff options
-rw-r--r-- | doio.c | 8 | ||||
-rw-r--r-- | pod/perldiag.pod | 23 | ||||
-rw-r--r-- | t/lib/warnings/doio | 39 |
3 files changed, 55 insertions, 15 deletions
@@ -536,12 +536,14 @@ Perl_do_openn(pTHX_ GV *gv, register char *name, I32 len, int as_raw, if ((IoTYPE(io) == IoTYPE_RDONLY) && (fp == PerlIO_stdout() || fp == PerlIO_stderr())) { Perl_warner(aTHX_ packWARN(WARN_IO), - "Filehandle STD%s opened only for input", - (fp == PerlIO_stdout()) ? "OUT" : "ERR"); + "Filehandle STD%s reopened as %s only for input", + ((fp == PerlIO_stdout()) ? "OUT" : "ERR"), + GvENAME(gv)); } else if ((IoTYPE(io) == IoTYPE_WRONLY) && fp == PerlIO_stdin()) { Perl_warner(aTHX_ packWARN(WARN_IO), - "Filehandle STDIN opened only for output"); + "Filehandle STDIN reopened as %s only for output", + GvENAME(gv)); } } diff --git a/pod/perldiag.pod b/pod/perldiag.pod index a0ef21a4a8..a08837d94f 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -1485,12 +1485,6 @@ PDP-11 or something? to be a read-write filehandle, you needed to open it with "+<" or "+>" or "+>>" instead of with "<" or nothing. If you intended only to write the file, use ">" or ">>". See L<perlfunc/open>. -The warning will also occur if STDOUT (file descriptor 1) or STDERR -(file descriptor 2) is opened for input, this is a pre-emptive warning in -case some other part of your program or a child process is expecting STDOUT -and STDERR to be writable. This can happen accidentally if you -C<close(STDOUT)> or STDERR and then C<open> an unrelated handle which -will resuse the lowest numbered available descriptor. =item Filehandle %s opened only for output @@ -1498,12 +1492,17 @@ will resuse the lowest numbered available descriptor. If you intended it to be a read/write filehandle, you needed to open it with "+<" or "+>" or "+>>" instead of with "<" or nothing. If you intended only to read from the file, use "<". See L<perlfunc/open>. -The warning will also occur if STDIN (file descriptor 0) is opened -for output - this is a pre-emptive warning in case some other part of your -program or a child process is expecting STDIN to be readable. -This can happen accidentally if you C<close(STDIN)> and then C<open> an -unrelated handle which will resuse the lowest numbered available -descriptor. + +=item Filehandle %s reopened as %s only for input + +(W io) You opened for reading a filehandle that got the same filehandle id +as STDOUT or STDERR. This occured because you closed STDOUT or STDERR +previously. + +=item Filehandle STDIN reopened as %s only for output + +(W io) You opened for writing a filehandle that got the same filehandle id +as STDIN. This occured because you closed STDIN previously. =item Final $ should be \$ or $name diff --git a/t/lib/warnings/doio b/t/lib/warnings/doio index bb09aa8552..15d4c5e957 100644 --- a/t/lib/warnings/doio +++ b/t/lib/warnings/doio @@ -275,3 +275,42 @@ no warnings 'io'; open FOO, '>', \$x; EXPECT Can't open a reference at - line 14. +######## +# doio.c [Perl_do_openn] +use Config; +BEGIN { + if (!$Config{useperlio}) { + print <<EOM; +SKIPPED +# warns only with perlio +EOM + exit; + } +} +use warnings 'io' ; +close STDOUT; +open FH1, "harness"; close FH1; +no warnings 'io' ; +open FH2, "harness"; close FH2; +EXPECT +Filehandle STDOUT reopened as FH1 only for input at - line 14. +######## +# doio.c [Perl_do_openn] +use Config; +BEGIN { + if (!$Config{useperlio}) { + print <<EOM; +SKIPPED +# warns only with perlio +EOM + exit; + } +} +use warnings 'io' ; +close STDIN; +open my $fh1, ">doiowarn.tmp"; close $fh1; +no warnings 'io' ; +open my $fh2, ">doiowarn.tmp"; close $fh2; +unlink "doiowarn.tmp"; +EXPECT +Filehandle STDIN reopened as $fh1 only for output at - line 14. |