From erik@phoenix.smluc.org  Sun Dec 22 15:32:56 2002
Return-Path: <erik@phoenix.smluc.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id D4AD337B401
	for <FreeBSD-gnats-submit@freebsd.org>; 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 <FreeBSD-gnats-submit@freebsd.org>; 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: patch to allow negative numbers in head

>Number:         46481
>Category:       bin
>Synopsis:       patch to allow negative numbers in head
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Dec 22 15:40:02 PST 2002
>Closed-Date:    Sun Dec 22 22:22:49 PST 2002
>Last-Modified:  Sun Dec 22 22:22:49 PST 2002
>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:
State-Changed-From-To: open->closed 
State-Changed-By: maxim 
State-Changed-When: Sun Dec 22 22:22:16 PST 2002 
State-Changed-Why:  
Duplicate of bin/46480. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=46481 
>Unformatted:
 To: FreeBSD-gnats-submit@freebsd.org
 From: Erik Greenwald <erik@smluc.org>
 Reply-To: Erik Greenwald <erik@smluc.org>
 Cc: erik@smluc.org
 X-send-pr-version: 3.113
 X-GNATS-Notify: 
 
 
