Skip site navigation (1)Skip section navigation (2)
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
Message-ID:  <200212222330.gBMNUcR20194@xarx.localdomain>

next in thread | raw e-mail | index | archive | help

>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 <erik@smluc.org>
 Reply-To: Erik Greenwald <erik@smluc.org>
 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200212222330.gBMNUcR20194>