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));
}
}
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
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
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.