From: Jonathan I. Kamens Date: Mon, 12 May 1997 11:47:13 +0000 (-0400) Subject: Make read with <> from a TTY notice EOF X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=451e086022facb7867a6764d6ffca2b71e86ff73;p=p5sagit%2Fp5-mst-13.2.git Make read with <> from a TTY notice EOF The patch I just sent in wasn't quite correct. I should have tested it more before sending it :-). Here's a correct patch. p5p-msgid: 199705121147.HAA03845@jik.saturn.net --- diff --git a/sv.c b/sv.c index 23b5c58..361d626 100644 --- a/sv.c +++ b/sv.c @@ -3253,7 +3253,25 @@ screamer2: memNE(SvPVX(sv) + SvCUR(sv) - rslen, rsptr, rslen))) { append = -1; - goto screamer2; + /* + If we're reading from a TTY and we get a short read, + indicating that the user hit his EOF character, we need + to notice it now, because if we try to read from the TTY + again, the EOF condition will disappear. + + The "(cnt == sizeof(buf))" check is an optimization to + prevent unnecessary calls to feof(). It seems safe + because as far as I can tell, whenever fread() returns a + full buffer, right before EOF, it will correctly return + 0 bytes on the next call, even when reading from a TTY. + However, I've only tested this on Linux; other platforms + may vary, so it might be easier just to remove the + optimization and just check for "! feof(fp)". + + - jik 9/25/96 + */ + if ((cnt == sizeof(buf)) || ! PerlIO_eof(fp)) + goto screamer2; } }