In order to perform faster when doing "head -n", use a pair of
fgetln/fwrite instead of getc/putchar, this seems about five times faster.
This commit is contained in:
parent
96b92e6726
commit
883f7cf969
@ -130,12 +130,13 @@ head(fp, cnt)
|
||||
FILE *fp;
|
||||
register int cnt;
|
||||
{
|
||||
register int ch;
|
||||
char *cp;
|
||||
int error, readlen;
|
||||
|
||||
while (cnt && (ch = getc(fp)) != EOF) {
|
||||
if (putchar(ch) == EOF)
|
||||
while (cnt && (cp = fgetln(fp, &readlen)) != NULL) {
|
||||
error = fwrite(cp, sizeof(char), readlen, stdout);
|
||||
if (error != readlen)
|
||||
err(1, "stdout");
|
||||
if (ch == '\n')
|
||||
cnt--;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user