diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 1998-07-05 22:11:21 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1998-07-05 22:11:21 +0000 |
commit | 0ce625782f64de805c21893bca308710ed297c68 (patch) | |
tree | bbb7692429e788be5e4821bed9a5c35c3666599e /pp_sys.c | |
parent | 76287dce09265df293372ba2775a5b0e95359fbe (diff) | |
download | perl-0ce625782f64de805c21893bca308710ed297c68.tar.gz |
fix getc() to return empty string instead of undef on eof, as it was
documented to behave; still returns undef on error
p4raw-id: //depot/perl@1327
Diffstat (limited to 'pp_sys.c')
-rw-r--r-- | pp_sys.c | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -889,6 +889,7 @@ PP(pp_getc) djSP; dTARGET; GV *gv; MAGIC *mg; + PerlIO *fp; if (MAXARG <= 0) gv = stdingv; @@ -910,11 +911,19 @@ PP(pp_getc) SvSetMagicSV_nosteal(TARG, TOPs); RETURN; } - if (!gv || do_eof(gv)) /* make sure we have fp with something */ + if (!gv || !GvIO(gv) || !(fp = IoIFP(GvIOp(gv)))) /* valid fp? */ RETPUSHUNDEF; + + if (do_eof(gv)) { /* handle magic argv, if needed */ + if (PerlIO_error(fp)) + PUSHs(&sv_undef); + else + PUSHp("",0); + RETURN; + } TAINT; sv_setpv(TARG, " "); - *SvPVX(TARG) = PerlIO_getc(IoIFP(GvIOp(gv))); /* should never be EOF */ + *SvPVX(TARG) = PerlIO_getc(fp); /* should never be EOF */ PUSHTARG; RETURN; } |