From: Gurusamy Sarathy Date: Sun, 5 Jul 1998 22:11:21 +0000 (+0000) Subject: fix getc() to return empty string instead of undef on eof, as it was X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0ce625782f64de805c21893bca308710ed297c68;p=p5sagit%2Fp5-mst-13.2.git 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 --- diff --git a/pp_sys.c b/pp_sys.c index 6fb7cb5..44e520b 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -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; }