This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
syswrite() wasn't reporting a warning when writing to a filehandle
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Sat, 23 Dec 2006 11:45:28 +0000 (11:45 +0000)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Sat, 23 Dec 2006 11:45:28 +0000 (11:45 +0000)
opened only for input.

p4raw-id: //depot/perl@29614

pp_sys.c
t/lib/warnings/pp_sys

index 6754c3e..53bffee 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1829,10 +1829,14 @@ PP(pp_send)
 
     SETERRNO(0,0);
     io = GvIO(gv);
-    if (!io || !IoIFP(io)) {
+    if (!io || !IoIFP(io) || IoTYPE(io) == IoTYPE_RDONLY) {
        retval = -1;
-       if (ckWARN(WARN_CLOSED))
-           report_evil_fh(gv, io, PL_op->op_type);
+       if (ckWARN2(WARN_UNOPENED,WARN_CLOSED)) {
+           if (io && IoIFP(io))
+               report_evil_fh(gv, io, OP_phoney_INPUT_ONLY);
+           else
+               report_evil_fh(gv, io, PL_op->op_type);
+       }
        SETERRNO(EBADF,RMS_IFI);
        goto say_undef;
     }
index 173d0d8..0dd3efe 100644 (file)
@@ -197,6 +197,14 @@ EXPECT
 Filehandle STDIN opened only for input at - line 3.
 ########
 # pp_sys.c [pp_send]
+use warnings 'io' ;
+syswrite STDIN, "fred";
+no warnings 'io' ;
+syswrite STDIN, "fred";
+EXPECT
+Filehandle STDIN opened only for input at - line 3.
+########
+# pp_sys.c [pp_send]
 use warnings 'closed' ;
 close STDIN; 
 syswrite STDIN, "fred", 1;