aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/head
diff options
context:
space:
mode:
authorMartin Tournoij <martin@arp242.net>2024-04-19 21:11:30 +0000
committerWarner Losh <imp@FreeBSD.org>2024-04-19 21:52:22 +0000
commit3abcc79c6a25fe9846be5a036d9a44086fb00163 (patch)
treec6ac38493a9716b4f9e5368ba8ffbc8667ba836b /usr.bin/head
parent9744821765fccd6c9b44d47804b6913cdf616d4e (diff)
downloadsrc-3abcc79c6a25fe9846be5a036d9a44086fb00163.tar.gz
src-3abcc79c6a25fe9846be5a036d9a44086fb00163.zip
Diffstat (limited to 'usr.bin/head')
-rw-r--r--usr.bin/head/head.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/usr.bin/head/head.c b/usr.bin/head/head.c
index 598d54b1c1ed..62796ae144a1 100644
--- a/usr.bin/head/head.c
+++ b/usr.bin/head/head.c
@@ -156,12 +156,13 @@ main(int argc, char *argv[])
static void
head(FILE *fp, intmax_t cnt)
{
- char *cp;
- size_t error, readlen;
+ char *cp = NULL;
+ size_t error, bufsize = 0;
+ ssize_t readlen;
- while (cnt != 0 && (cp = fgetln(fp, &readlen)) != NULL) {
+ while (cnt != 0 && (readlen = getline(&cp, &bufsize, fp)) >= 0) {
error = fwrite(cp, sizeof(char), readlen, stdout);
- if (error != readlen)
+ if ((ssize_t)error != readlen)
err(1, "stdout");
cnt--;
}