From: Nick Ing-Simmons Date: Sun, 5 Nov 2000 10:10:13 +0000 (+0000) Subject: Fix case where ungetc(f,EOF) was allowed. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=313ca112ae76354c03e7aff0a3e35062e8173ef0;p=p5sagit%2Fp5-mst-13.2.git Fix case where ungetc(f,EOF) was allowed. Move PerlIO_ungetc() near PerlIO_putc()/PerlIO_getc() in the file so we can see similarities. Use types more carefully and a STDCHAR array in hope that this will fix Jarrko's 64bit machine. p4raw-id: //depot/perlio@7554 --- diff --git a/perlio.c b/perlio.c index 5d8ecdb..9774c3c 100644 --- a/perlio.c +++ b/perlio.c @@ -372,7 +372,7 @@ PerlIO_default_layer(I32 n) av_push(PerlIO_layer_av,SvREFCNT_inc(layer)); } else - Perl_croak(aTHX_ "Unknown layer %.*s",(e-s),s); + Perl_warn(aTHX_ "Unknown layer %.*s",(e-s),s); s = e; } } @@ -513,14 +513,11 @@ PerlIO_read(PerlIO *f, void *vbuf, Size_t count) return (*PerlIOBase(f)->tab->Read)(f,vbuf,count); } -#undef PerlIO_ungetc -int -PerlIO_ungetc(PerlIO *f, int ch) +#undef PerlIO_unread +SSize_t +PerlIO_unread(PerlIO *f, const void *vbuf, Size_t count) { - STDCHAR buf = ch; - if ((*PerlIOBase(f)->tab->Unread)(f,&buf,1) == 1) - return ch; - return -1; + return (*PerlIOBase(f)->tab->Unread)(f,vbuf,count); } #undef PerlIO_write @@ -1776,11 +1773,26 @@ PerlIO_getname(PerlIO *f, char *buf) int PerlIO_getc(PerlIO *f) { - STDCHAR buf; - int count = PerlIO_read(f,&buf,1); + STDCHAR buf[1]; + SSize_t count = PerlIO_read(f,buf,1); if (count == 1) - return (unsigned char) buf; - return -1; + { + return (unsigned char) buf[0]; + } + return EOF; +} + +#undef PerlIO_ungetc +int +PerlIO_ungetc(PerlIO *f, int ch) +{ + if (ch != EOF) + { + STDCHAR buf = ch; + if (PerlIO_unread(f,&buf,1) == 1) + return ch; + } + return EOF; } #undef PerlIO_putc