From 710668cad452c0d21e7de1a8ac53685d16bdedf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Fri, 9 Oct 1998 10:33:46 +0000 Subject: [PATCH] fread() returns 0 on eof or error, not EOF. This fixes the following bug: "head -c " never exit and loops forever (until it is killed), if the input stream has fewer bytes than specified (n). PR: bin/8225 Submitted-by: FUJIMOTO Kensaku --- usr.bin/head/head.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr.bin/head/head.c b/usr.bin/head/head.c index 632660503831..fc4bdf61664b 100644 --- a/usr.bin/head/head.c +++ b/usr.bin/head/head.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)head.c 8.2 (Berkeley) 5/4/95"; #endif static const char rcsid[] = - "$Id: head.c,v 1.7 1997/07/10 06:46:13 charnier Exp $"; + "$Id: head.c,v 1.8 1997/07/11 06:13:18 charnier Exp $"; #endif /* not lint */ #include @@ -157,7 +157,7 @@ head_bytes(fp, cnt) else readlen = sizeof(buf); readlen = fread(buf, sizeof(char), readlen, fp); - if (readlen == EOF) + if (readlen == 0) break; if (fwrite(buf, sizeof(char), readlen, stdout) != readlen) err(1, "stdout");