From owner-freebsd-bugs Sun Dec 22 15:40: 9 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3443537B405 for ; Sun, 22 Dec 2002 15:40:04 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8C60243EF2 for ; Sun, 22 Dec 2002 15:40:02 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id gBMNe2NS076883 for ; Sun, 22 Dec 2002 15:40:02 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id gBMNe29n076882; Sun, 22 Dec 2002 15:40:02 -0800 (PST) Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AE95537B401 for ; Sun, 22 Dec 2002 15:30:25 -0800 (PST) Received: from mailout3-eri1.midsouth.rr.com (mailout3-eri1.midsouth.rr.com [24.165.200.8]) by mx1.FreeBSD.org (Postfix) with ESMTP id 17B9C43EE6 for ; Sun, 22 Dec 2002 15:30:20 -0800 (PST) (envelope-from erik@phoenix.smluc.org) Received: from xarx.localdomain (root@cpe-066-061-038-083.midsouth.rr.com [66.61.38.83]) by mailout3-eri1.midsouth.rr.com (8.11.4/8.11.4) with ESMTP id gBMNUIa04234 for ; Sun, 22 Dec 2002 17:30:19 -0600 (CST) Received: (from erik@localhost) by xarx.localdomain (8.11.6/8.11.6) id gBMNUcR20194 for FreeBSD-gnats-submit@freebsd.org; Sun, 22 Dec 2002 17:30:38 -0600 Message-Id: <200212222330.gBMNUcR20194@xarx.localdomain> Date: Sun, 22 Dec 2002 17:30:38 -0600 From: erik@phoenix.smluc.org To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/46480: patch to allow negative numbers in head Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 46480 >Category: bin >Synopsis: patch to allow negative numbers in head >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Dec 22 15:40:01 PST 2002 >Closed-Date: >Last-Modified: >Originator: Erik Greenwald >Release: FreeBSD 5.0-CURRENT i386 >Organization: >Environment: System: FreeBSD fenris 5.0-CURRENT FreeBSD 5.0-CURRENT #3: Sun Dec 22 15:57:51 CST 2002 root@fenris:/usr/src/sys/i386/compile/FENRIS i386 >Description: Patch to allow negative numbers in head. When given a negative number, it prints all of the file EXCEPT the first N lines. (initiated by irc bs with larne, rockshox, and hideaway) >How-To-Repeat: >Fix: --- head.patch begins here --- --- usr.bin/head/head.c.orig Sun Dec 22 16:49:02 2002 +++ usr.bin/head/head.c Sun Dec 22 17:15:43 2002 @@ -83,7 +83,7 @@ break; case 'n': linecnt = strtol(optarg, &ep, 10); - if (*ep || linecnt <= 0) + if (*ep || linecnt == 0) errx(1, "illegal line count -- %s", optarg); break; case '?': @@ -129,11 +129,22 @@ char *cp; size_t error, readlen; + if(cnt>0) while (cnt && (cp = fgetln(fp, &readlen)) != NULL) { error = fwrite(cp, sizeof(char), readlen, stdout); if (error != readlen) err(1, "stdout"); cnt--; + } + else { + while (++cnt) + if (fgetln(fp, &readlen) == NULL) + return; + while ((cp = fgetln(fp, &readlen)) != NULL) { + error = fwrite(cp, sizeof(char), readlen, stdout); + if (error != readlen) + err(1, "stdout"); + } } } --- head.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted: To: FreeBSD-gnats-submit@freebsd.org From: Erik Greenwald Reply-To: Erik Greenwald Cc: erik@smluc.org X-send-pr-version: 3.113 X-GNATS-Notify: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message