From fa972955217712cc70fc90adcd8f63c15912f2ea Mon Sep 17 00:00:00 2001 From: brooks Date: Thu, 11 Jan 2007 17:03:51 +0000 Subject: [PATCH] Fix head -c ### where ### is greater than 2^31. Unlike the submitted patch this uses off_t. WARNSify and add $FreeBSD$ to Makefile. PR: bin/107824 Submitted by: Brian Cornell MFC after: 3 days --- usr.bin/head/Makefile | 2 ++ usr.bin/head/head.c | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/usr.bin/head/Makefile b/usr.bin/head/Makefile index b0b911ece450..002b3f385b3e 100644 --- a/usr.bin/head/Makefile +++ b/usr.bin/head/Makefile @@ -1,5 +1,7 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 +# $FreeBSD$ PROG= head +WARNS= 6 .include diff --git a/usr.bin/head/head.c b/usr.bin/head/head.c index eb20446ec636..36aa9bf6cae5 100644 --- a/usr.bin/head/head.c +++ b/usr.bin/head/head.c @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -61,7 +62,7 @@ __FBSDID("$FreeBSD$"); */ static void head(FILE *, int); -static void head_bytes(FILE *, size_t); +static void head_bytes(FILE *, off_t); static void obsolete(char *[]); static void usage(void); @@ -70,14 +71,15 @@ main(int argc, char *argv[]) { int ch; FILE *fp; - int first, linecnt = -1, bytecnt = -1, eval = 0; + int first, linecnt = -1, eval = 0; + off_t bytecnt = -1; char *ep; obsolete(argv); while ((ch = getopt(argc, argv, "n:c:")) != -1) switch(ch) { case 'c': - bytecnt = strtol(optarg, &ep, 10); + bytecnt = strtoimax(optarg, &ep, 10); if (*ep || bytecnt <= 0) errx(1, "illegal byte count -- %s", optarg); break; @@ -138,7 +140,7 @@ head(FILE *fp, int cnt) } static void -head_bytes(FILE *fp, size_t cnt) +head_bytes(FILE *fp, off_t cnt) { char buf[4096]; size_t readlen;