diff options
author | Nick Ing-Simmons <nik@tiuk.ti.com> | 2001-03-22 11:59:44 +0000 |
---|---|---|
committer | Nick Ing-Simmons <nik@tiuk.ti.com> | 2001-03-22 11:59:44 +0000 |
commit | a00b5bd33cb12556305f4526d4870e67e2ca9517 (patch) | |
tree | 65c1599bac3840ee1c5d7c50de5268b31e9305f8 /doio.c | |
parent | 4a7d1889681c73a99b9a39d8a3d3760367674002 (diff) | |
download | perl-a00b5bd33cb12556305f4526d4870e67e2ca9517.tar.gz |
If stdin, stdout or stderr get opened in unexpected read/write state
then warn at time of open not at time of use.
p4raw-id: //depot/perlio@9295
Diffstat (limited to 'doio.c')
-rw-r--r-- | doio.c | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -463,6 +463,18 @@ Perl_do_openn(pTHX_ GV *gv, register char *name, I32 len, int as_raw, Perl_warner(aTHX_ WARN_NEWLINE, PL_warn_nl, "open"); goto say_false; } + + if (ckWARN(WARN_IO)) { + if ((IoTYPE(io) == IoTYPE_RDONLY) && + (fp == PerlIO_stdout() || fp == PerlIO_stderr())) { + Perl_warner(aTHX_ WARN_IO, "'std%s' opened only for input", + (fp == PerlIO_stdout()) ? "out" : "err"); + } + else if ((IoTYPE(io) == IoTYPE_WRONLY) && fp == PerlIO_stdout()) { + Perl_warner(aTHX_ WARN_IO, "'stdin' opened only for output"); + } + } + if (IoTYPE(io) && IoTYPE(io) != IoTYPE_PIPE && IoTYPE(io) != IoTYPE_STD) { if (PerlLIO_fstat(PerlIO_fileno(fp),&PL_statbuf) < 0) { (void)PerlIO_close(fp); @@ -938,9 +950,7 @@ Perl_do_eof(pTHX_ GV *gv) if (!io) return TRUE; - else if (ckWARN(WARN_IO) - && (IoTYPE(io) == IoTYPE_WRONLY || IoIFP(io) == PerlIO_stdout() - || IoIFP(io) == PerlIO_stderr())) + else if (ckWARN(WARN_IO) && (IoTYPE(io) == IoTYPE_WRONLY)) { /* integrate to report_evil_fh()? */ char *name = NULL; |