diff options
author | alfred <alfred@FreeBSD.org> | 2001-11-02 09:27:16 +0000 |
---|---|---|
committer | alfred <alfred@FreeBSD.org> | 2001-11-02 09:27:16 +0000 |
commit | 883f7cf9695d432c4eee9356f572dee4614e0116 (patch) | |
tree | 3a77da26454582e493608fc063fa8d1679d9e2b2 /usr.bin/head | |
parent | 96b92e67264521fc24556e40bed6f64edbab1379 (diff) | |
download | FreeBSD-src-883f7cf9695d432c4eee9356f572dee4614e0116.zip FreeBSD-src-883f7cf9695d432c4eee9356f572dee4614e0116.tar.gz |
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.
Diffstat (limited to 'usr.bin/head')
-rw-r--r-- | usr.bin/head/head.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/usr.bin/head/head.c b/usr.bin/head/head.c index d262a95..6af287c1 100644 --- a/usr.bin/head/head.c +++ b/usr.bin/head/head.c @@ -130,14 +130,15 @@ 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) - err(1, "stdout"); - if (ch == '\n') - cnt--; - } + while (cnt && (cp = fgetln(fp, &readlen)) != NULL) { + error = fwrite(cp, sizeof(char), readlen, stdout); + if (error != readlen) + err(1, "stdout"); + cnt--; + } } void |