From 6ebe32537f9689d704daaa1207b4518a57085b2f Mon Sep 17 00:00:00 2001 From: charnier Date: Thu, 10 Jul 1997 06:46:13 +0000 Subject: Use err(3) instead of local redefinition. --- usr.bin/head/head.c | 56 ++++++++++++++--------------------------------------- 1 file changed, 14 insertions(+), 42 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/head/head.c b/usr.bin/head/head.c index e4a7a58..4fb2b0f 100644 --- a/usr.bin/head/head.c +++ b/usr.bin/head/head.c @@ -32,19 +32,23 @@ */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1980, 1987, 1992, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint +#if 0 static char sccsid[] = "@(#)head.c 8.2 (Berkeley) 5/4/95"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include #include -#include +#include #include #include #include @@ -56,7 +60,6 @@ static char sccsid[] = "@(#)head.c 8.2 (Berkeley) 5/4/95"; * Bill Joy UCB August 24, 1977 */ -void err __P((int, const char *, ...)); void head __P((FILE *, int)); void head_bytes __P((FILE *, int)); void obsolete __P((char *[])); @@ -80,12 +83,12 @@ main(argc, argv) case 'c': bytecnt = strtol(optarg, &ep, 10); if (*ep || bytecnt <= 0) - err(1, "illegal byte count -- %s", optarg); + errx(1, "illegal byte count -- %s", optarg); break; case 'n': linecnt = strtol(optarg, &ep, 10); if (*ep || linecnt <= 0) - err(1, "illegal line count -- %s", optarg); + errx(1, "illegal line count -- %s", optarg); break; case '?': default: @@ -95,13 +98,13 @@ main(argc, argv) argv += optind; if (linecnt != -1 && bytecnt != -1) - err(1, "can't combine line and byte counts"); + errx(1, "can't combine line and byte counts"); if (linecnt == -1 ) linecnt = 10; if (*argv) { for (first = 1; *argv; ++argv) { if ((fp = fopen(*argv, "r")) == NULL) { - err(0, "%s: %s", *argv, strerror(errno)); + warn("%s", *argv); continue; } if (argc > 1) { @@ -133,7 +136,7 @@ head(fp, cnt) while (cnt && (ch = getc(fp)) != EOF) { if (putchar(ch) == EOF) - err(1, "stdout: %s", strerror(errno)); + err(1, "stdout"); if (ch == '\n') cnt--; } @@ -156,7 +159,7 @@ head_bytes(fp, cnt) if (readlen == EOF) break; if (fwrite(buf, sizeof(char), readlen, stdout) != readlen) - err(1, "stdout: %s", strerror(errno)); + err(1, "stdout"); cnt -= readlen; } } @@ -172,7 +175,7 @@ obsolete(argv) if (ap[0] != '-' || ap[1] == '-' || !isdigit(ap[1])) return; if ((ap = malloc(strlen(*argv) + 2)) == NULL) - err(1, "%s", strerror(errno)); + err(1, NULL); ap[0] = '-'; ap[1] = 'n'; (void)strcpy(ap + 2, *argv + 1); @@ -183,37 +186,6 @@ obsolete(argv) void usage() { - (void)fprintf(stderr, "usage: head [-n lines] [file ...]\n"); + (void)fprintf(stderr, "usage: head [-n lines] [-c bytes] [file ...]\n"); exit(1); } - -#if __STDC__ -#include -#else -#include -#endif - -void -#if __STDC__ -err(int fatal, const char *fmt, ...) -#else -err(fatal, fmt, va_alist) - int fatal; - char *fmt; - va_dcl -#endif -{ - va_list ap; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - (void)fprintf(stderr, "head: "); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fprintf(stderr, "\n"); - if (fatal) - exit(1); - eval = 1; -} -- cgit v1.1