summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-07-10 06:46:13 +0000
committercharnier <charnier@FreeBSD.org>1997-07-10 06:46:13 +0000
commit6ebe32537f9689d704daaa1207b4518a57085b2f (patch)
tree1c11a4a7302807a85a3072398717783ce0fc1163 /usr.bin
parent3e5d2f9ca56d4333f70c1ca8d3b4c882ace01e89 (diff)
downloadFreeBSD-src-6ebe32537f9689d704daaa1207b4518a57085b2f.zip
FreeBSD-src-6ebe32537f9689d704daaa1207b4518a57085b2f.tar.gz
Use err(3) instead of local redefinition.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/head/head.c56
1 files changed, 14 insertions, 42 deletions
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 <sys/types.h>
#include <ctype.h>
-#include <errno.h>
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -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 <stdarg.h>
-#else
-#include <varargs.h>
-#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;
-}
OpenPOWER on IntegriCloud