Date: Mon, 26 Feb 1996 09:08:49 +0200 (SAT) From: R Bezuidenhout <rbezuide@mikom.csir.co.za> To: hackers@freebsd.org Subject: Extra entry with /usr/bin/head ?? Message-ID: <199602260708.JAA02345@zibbi.mikom.csir.co.za>
next in thread | raw e-mail | index | archive | help
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')
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199602260708.JAA02345>