CVS commit: src/usr.bin/head
Module Name:src Committed By: wiz Date: Tue Jul 4 06:59:35 UTC 2017 Modified Files: src/usr.bin/head: head.1 Log Message: Add EXIT STATUS section. Use Ex. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/usr.bin/head/head.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/head/head.1 diff -u src/usr.bin/head/head.1:1.13 src/usr.bin/head/head.1:1.14 --- src/usr.bin/head/head.1:1.13 Mon Jul 3 21:34:19 2017 +++ src/usr.bin/head/head.1 Tue Jul 4 06:59:34 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: head.1,v 1.13 2017/07/03 21:34:19 wiz Exp $ +.\" $NetBSD: head.1,v 1.14 2017/07/04 06:59:34 wiz Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -65,10 +65,8 @@ is the name of the file. The .Fl q flag disables the printing of the header in all cases. -.Pp -The -.Nm -utility exits 0 on success, and >0 if an error occurs. +.Sh EXIT STATUS +.Ex -std head .Sh COMPATIBILITY The historic command line syntax of .Nm
CVS commit: src/usr.bin/head
Module Name:src Committed By: wiz Date: Tue Jul 4 06:59:35 UTC 2017 Modified Files: src/usr.bin/head: head.1 Log Message: Add EXIT STATUS section. Use Ex. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/usr.bin/head/head.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/head
Module Name:src Committed By: nonaka Date: Thu May 12 01:56:44 UTC 2016 Modified Files: src/usr.bin/head: head.c Log Message: If the negative number is passed to option '-c' or '-n', it should occur an error. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/usr.bin/head/head.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/head/head.c diff -u src/usr.bin/head/head.c:1.23 src/usr.bin/head/head.c:1.24 --- src/usr.bin/head/head.c:1.23 Wed Mar 31 21:55:23 2010 +++ src/usr.bin/head/head.c Thu May 12 01:56:44 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: head.c,v 1.23 2010/03/31 21:55:23 joerg Exp $ */ +/* $NetBSD: head.c,v 1.24 2016/05/12 01:56:44 nonaka Exp $ */ /* * Copyright (c) 1980, 1987, 1992, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)head.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: head.c,v 1.23 2010/03/31 21:55:23 joerg Exp $"); +__RCSID("$NetBSD: head.c,v 1.24 2016/05/12 01:56:44 nonaka Exp $"); #endif #endif /* not lint */ @@ -73,8 +73,8 @@ main(int argc, char *argv[]) int ch; FILE *fp; int first; - uintmax_t linecnt; - uintmax_t bytecnt; + intmax_t linecnt; + intmax_t bytecnt; char *ep; int eval = 0; int qflag = 0;
CVS commit: src/usr.bin/head
Module Name:src Committed By: nonaka Date: Thu May 12 01:56:44 UTC 2016 Modified Files: src/usr.bin/head: head.c Log Message: If the negative number is passed to option '-c' or '-n', it should occur an error. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/usr.bin/head/head.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/head
Module Name:src Committed By: joerg Date: Wed Mar 31 15:01:02 UTC 2010 Modified Files: src/usr.bin/head: head.c Log Message: ANSIfy. Sprinkle static. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/usr.bin/head/head.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/head/head.c diff -u src/usr.bin/head/head.c:1.19 src/usr.bin/head/head.c:1.20 --- src/usr.bin/head/head.c:1.19 Mon Jul 21 14:19:23 2008 +++ src/usr.bin/head/head.c Wed Mar 31 15:01:02 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: head.c,v 1.19 2008/07/21 14:19:23 lukem Exp $ */ +/* $NetBSD: head.c,v 1.20 2010/03/31 15:01:02 joerg Exp $ */ /* * Copyright (c) 1980, 1987, 1992, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = @(#)head.c 8.2 (Berkeley) 5/4/95; #else -__RCSID($NetBSD: head.c,v 1.19 2008/07/21 14:19:23 lukem Exp $); +__RCSID($NetBSD: head.c,v 1.20 2010/03/31 15:01:02 joerg Exp $); #endif #endif /* not lint */ @@ -61,17 +61,14 @@ * Bill Joy UCB August 24, 1977 */ -void head __P((FILE *, long, long)); -void obsolete __P((char *[])); -void usage __P((void)); -int main __P((int, char *[])); +static void head(FILE *, long, long); +static void obsolete(char *[]); +__dead static void usage(void); int eval = 0; int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { int ch; FILE *fp; @@ -145,11 +142,8 @@ exit(eval); } -void -head(fp, cnt, bytecnt) - FILE *fp; - long cnt; - long bytecnt; +static void +head(FILE *fp, long cnt, long bytecnt) { int ch; @@ -164,9 +158,8 @@ } } -void -obsolete(argv) - char *argv[]; +static void +obsolete(char *argv[]) { char *ap; @@ -184,8 +177,8 @@ } } -void -usage() +static void +usage(void) { (void)fprintf(stderr, usage: %s [-n lines] [file ...]\n,
CVS commit: src/usr.bin/head
Module Name:src Committed By: joerg Date: Wed Mar 31 15:01:51 UTC 2010 Modified Files: src/usr.bin/head: head.c Log Message: Make eval a local variable. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/usr.bin/head/head.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/head/head.c diff -u src/usr.bin/head/head.c:1.20 src/usr.bin/head/head.c:1.21 --- src/usr.bin/head/head.c:1.20 Wed Mar 31 15:01:02 2010 +++ src/usr.bin/head/head.c Wed Mar 31 15:01:51 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: head.c,v 1.20 2010/03/31 15:01:02 joerg Exp $ */ +/* $NetBSD: head.c,v 1.21 2010/03/31 15:01:51 joerg Exp $ */ /* * Copyright (c) 1980, 1987, 1992, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = @(#)head.c 8.2 (Berkeley) 5/4/95; #else -__RCSID($NetBSD: head.c,v 1.20 2010/03/31 15:01:02 joerg Exp $); +__RCSID($NetBSD: head.c,v 1.21 2010/03/31 15:01:51 joerg Exp $); #endif #endif /* not lint */ @@ -65,7 +65,6 @@ static void obsolete(char *[]); __dead static void usage(void); -int eval = 0; int main(int argc, char *argv[]) @@ -76,6 +75,7 @@ long linecnt; long bytecnt; char *ep; + int eval = 0; int qflag = 0; int vflag = 0;
CVS commit: src/usr.bin/head
Module Name:src Committed By: joerg Date: Wed Mar 31 21:52:11 UTC 2010 Modified Files: src/usr.bin/head: head.c Log Message: Remove 2**31 limit on the number of lines or bytes to process. For the byte operations, process in blocks of 64KB. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/usr.bin/head/head.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/head/head.c diff -u src/usr.bin/head/head.c:1.21 src/usr.bin/head/head.c:1.22 --- src/usr.bin/head/head.c:1.21 Wed Mar 31 15:01:51 2010 +++ src/usr.bin/head/head.c Wed Mar 31 21:52:11 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: head.c,v 1.21 2010/03/31 15:01:51 joerg Exp $ */ +/* $NetBSD: head.c,v 1.22 2010/03/31 21:52:11 joerg Exp $ */ /* * Copyright (c) 1980, 1987, 1992, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = @(#)head.c 8.2 (Berkeley) 5/4/95; #else -__RCSID($NetBSD: head.c,v 1.21 2010/03/31 15:01:51 joerg Exp $); +__RCSID($NetBSD: head.c,v 1.22 2010/03/31 21:52:11 joerg Exp $); #endif #endif /* not lint */ @@ -48,6 +48,7 @@ #include ctype.h #include err.h #include errno.h +#include inttypes.h #include limits.h #include locale.h #include stdio.h @@ -61,7 +62,7 @@ * Bill Joy UCB August 24, 1977 */ -static void head(FILE *, long, long); +static void head(FILE *, intmax_t, intmax_t); static void obsolete(char *[]); __dead static void usage(void); @@ -72,8 +73,8 @@ int ch; FILE *fp; int first; - long linecnt; - long bytecnt; + uintmax_t linecnt; + uintmax_t bytecnt; char *ep; int eval = 0; int qflag = 0; @@ -87,22 +88,18 @@ switch(ch) { case 'c': errno = 0; - bytecnt = strtol(optarg, ep, 10); - if ((bytecnt == LONG_MIN || bytecnt == LONG_MAX) - errno == ERANGE) + bytecnt = strtoimax(optarg, ep, 10); + if ((bytecnt == INTMAX_MAX errno == ERANGE) || + *ep || bytecnt = 0) err(1, illegal byte count -- %s, optarg); - else if (*ep || bytecnt = 0) -errx(1, illegal byte count -- %s, optarg); break; case 'n': errno = 0; - linecnt = strtol(optarg, ep, 10); - if ((linecnt == LONG_MIN || linecnt == LONG_MAX) - errno == ERANGE) + linecnt = strtoimax(optarg, ep, 10); + if ((linecnt == INTMAX_MAX errno == ERANGE) || + *ep || linecnt = 0) err(1, illegal line count -- %s, optarg); - else if (*ep || linecnt = 0) -errx(1, illegal line count -- %s, optarg); break; case 'q': @@ -143,19 +140,39 @@ } static void -head(FILE *fp, long cnt, long bytecnt) +head(FILE *fp, intmax_t cnt, intmax_t bytecnt) { + char buf[65536]; + size_t len, rv, rv2; int ch; - if (bytecnt) - cnt = bytecnt; - while (cnt--) + if (bytecnt) { + while (bytecnt) { + len = sizeof(buf); + if (bytecnt (intmax_t)sizeof(buf)) +len = sizeof(buf); + else +len = bytecnt; + rv = fread(buf, 1, len, fp); + if (rv == 0) +break; /* Distinguish EOF and error? */ + rv2 = fwrite(buf, 1, rv, stdout); + if (rv2 != rv) { +if (feof(stdout)) + errx(1, EOF on stdout); +else + err(1, failure writing to stdout); + } + bytecnt -= rv; + } + } else { while ((ch = getc(fp)) != EOF) { if (putchar(ch) == EOF) err(1, stdout); - if (ch == '\n' || bytecnt) + if (ch == '\n' --cnt == 0) break; } + } } static void
CVS commit: src/usr.bin/head
Module Name:src Committed By: joerg Date: Wed Mar 31 21:55:23 UTC 2010 Modified Files: src/usr.bin/head: head.c Log Message: Just ignore the errno of strtoimax, it doesn't provide much value. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/usr.bin/head/head.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/head/head.c diff -u src/usr.bin/head/head.c:1.22 src/usr.bin/head/head.c:1.23 --- src/usr.bin/head/head.c:1.22 Wed Mar 31 21:52:11 2010 +++ src/usr.bin/head/head.c Wed Mar 31 21:55:23 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: head.c,v 1.22 2010/03/31 21:52:11 joerg Exp $ */ +/* $NetBSD: head.c,v 1.23 2010/03/31 21:55:23 joerg Exp $ */ /* * Copyright (c) 1980, 1987, 1992, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = @(#)head.c 8.2 (Berkeley) 5/4/95; #else -__RCSID($NetBSD: head.c,v 1.22 2010/03/31 21:52:11 joerg Exp $); +__RCSID($NetBSD: head.c,v 1.23 2010/03/31 21:55:23 joerg Exp $); #endif #endif /* not lint */ @@ -91,7 +91,7 @@ bytecnt = strtoimax(optarg, ep, 10); if ((bytecnt == INTMAX_MAX errno == ERANGE) || *ep || bytecnt = 0) -err(1, illegal byte count -- %s, optarg); +errx(1, illegal byte count -- %s, optarg); break; case 'n': @@ -99,7 +99,7 @@ linecnt = strtoimax(optarg, ep, 10); if ((linecnt == INTMAX_MAX errno == ERANGE) || *ep || linecnt = 0) -err(1, illegal line count -- %s, optarg); +errx(1, illegal line count -- %s, optarg); break; case 'q':
CVS commit: src/usr.bin/head
Module Name:src Committed By: joerg Date: Wed Mar 31 15:01:02 UTC 2010 Modified Files: src/usr.bin/head: head.c Log Message: ANSIfy. Sprinkle static. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/usr.bin/head/head.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/head
Module Name:src Committed By: joerg Date: Wed Mar 31 15:01:51 UTC 2010 Modified Files: src/usr.bin/head: head.c Log Message: Make eval a local variable. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/usr.bin/head/head.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.