From 0ce625782f64de805c21893bca308710ed297c68 Mon Sep 17 00:00:00 2001 From: Gurusamy Sarathy Date: Sun, 5 Jul 1998 22:11:21 +0000 Subject: [PATCH] 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 --- pp_sys.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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; } -- 2.7.4