summaryrefslogtreecommitdiff
path: root/pp_sys.c
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1998-07-05 22:11:21 +0000
committerGurusamy Sarathy <gsar@cpan.org>1998-07-05 22:11:21 +0000
commit0ce625782f64de805c21893bca308710ed297c68 (patch)
treebbb7692429e788be5e4821bed9a5c35c3666599e /pp_sys.c
parent76287dce09265df293372ba2775a5b0e95359fbe (diff)
downloadperl-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.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/pp_sys.c b/pp_sys.c
index 6fb7cb5f18..44e520be20 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;
}