head(1) ignored EOFs (in certain cases).

Closes PR # bin/678: head(1) ignore EOF

Submitted by:	wosch@cs.tu-berlin.de (Wolfram Schneider)
This commit is contained in:
Joerg Wunsch 1995-08-15 19:34:11 +00:00
parent a722b904d7
commit 8e502f1158
1 changed files with 2 additions and 3 deletions

View File

@ -113,12 +113,11 @@ head(fp, cnt)
{
register int ch;
while (cnt--)
while ((ch = getc(fp)) != EOF) {
while ((ch = getc(fp)) != EOF && cnt) {
if (putchar(ch) == EOF)
err(1, "stdout: %s", strerror(errno));
if (ch == '\n')
break;
cnt--;
}
}