From owner-freebsd-bugs Sun Dec 22 15:40: 6 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 1F40A37B401 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 0C39843EF7 for ; Sun, 22 Dec 2002 15:40:03 -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 gBMNe2NS076897 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 gBMNe2oZ076896; 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 D4AD337B401 for ; Sun, 22 Dec 2002 15:32:56 -0800 (PST) Received: from phoenix.smluc.org (phoenix.smluc.org [12.10.110.235]) by mx1.FreeBSD.org (Postfix) with SMTP id 3CD4743EDA for ; Sun, 22 Dec 2002 15:32:56 -0800 (PST) (envelope-from erik@phoenix.smluc.org) Received: (qmail 26929 invoked by uid 1000); 22 Dec 2002 23:33:02 -0000 Message-Id: <20021222233302.26928.qmail@phoenix.smluc.org> Date: 22 Dec 2002 23:33:02 -0000 From: erik@phoenix.smluc.org To: FreeBSD-gnats-submit@FreeBSD.org Cc: erik@smluc.org Subject: bin/46481: 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: 46481 >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:02 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