From owner-freebsd-hackers Sun Feb 25 23:12:29 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id XAA29716 for hackers-outgoing; Sun, 25 Feb 1996 23:12:29 -0800 (PST) Received: from zibbi.mikom.csir.co.za (zibbi.mikom.csir.co.za [146.64.24.58]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id XAA29695 for ; Sun, 25 Feb 1996 23:11:55 -0800 (PST) Received: (from rbezuide@localhost) by zibbi.mikom.csir.co.za (8.6.12/8.6.9) id JAA02345 for hackers@freebsd.org; Mon, 26 Feb 1996 09:08:50 +0200 From: R Bezuidenhout Message-Id: <199602260708.JAA02345@zibbi.mikom.csir.co.za> Subject: Extra entry with /usr/bin/head ?? To: hackers@freebsd.org Date: Mon, 26 Feb 1996 09:08:49 +0200 (SAT) X-Mailer: ELM [version 2.4 PL24 ME8b] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@freebsd.org Precedence: bulk Hi all ... I have been experiencing the following "problem" with head in FreeBSD 2.1-STABLE. Head has the option -n for specifying the number of lines to scan, but the following happens. > head -n 1 YES YES h <- head wants an extra entry here before returning ? > This is the same with every number you give head. I had a look in the source code and made the following change which changes the sequence of tests in the while statement. This will cause head to first check the count and then get the next line of characters and not cause it to first get the characters even if the count (cnt) has become 0. Thanx ... *** /usr/src/usr.bin/head/head.c Mon Aug 28 07:36:45 1995 --- ./head.c Mon Feb 26 08:55:39 1996 *************** *** 113,119 **** { register int ch; ! while ((ch = getc(fp)) != EOF && cnt) { if (putchar(ch) == EOF) err(1, "stdout: %s", strerror(errno)); if (ch == '\n') --- 113,119 ---- { register int ch; ! while (cnt && (ch = getc(fp)) != EOF) { if (putchar(ch) == EOF) err(1, "stdout: %s", strerror(errno)); if (ch == '\n')