summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-07-10 06:48:24 +0000
committercharnier <charnier@FreeBSD.org>1997-07-10 06:48:24 +0000
commitc4ced555e147c0328b1ac46abe1b7b5f63b1c251 (patch)
tree393f17c41d577ae35a6b7bbd2f07fc43da455975 /usr.bin
parent6ebe32537f9689d704daaa1207b4518a57085b2f (diff)
downloadFreeBSD-src-c4ced555e147c0328b1ac46abe1b7b5f63b1c251.zip
FreeBSD-src-c4ced555e147c0328b1ac46abe1b7b5f63b1c251.tar.gz
Use err(3) instead of local redefinition, incorporate `hd' in usage str.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/hexdump/display.c20
-rw-r--r--usr.bin/hexdump/hexdump.c36
-rw-r--r--usr.bin/hexdump/hexdump.h1
-rw-r--r--usr.bin/hexdump/hexsyntax.c16
-rw-r--r--usr.bin/hexdump/odsyntax.c13
-rw-r--r--usr.bin/hexdump/parse.c20
6 files changed, 48 insertions, 58 deletions
diff --git a/usr.bin/hexdump/display.c b/usr.bin/hexdump/display.c
index 8078e71..0a74542 100644
--- a/usr.bin/hexdump/display.c
+++ b/usr.bin/hexdump/display.c
@@ -32,18 +32,22 @@
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
#include <ctype.h>
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include "hexdump.h"
enum _vflag vflag = FIRST;
@@ -263,8 +267,7 @@ get()
length == -1 ? need : MIN(length, need), stdin);
if (!n) {
if (ferror(stdin))
- (void)fprintf(stderr, "hexdump: %s: %s\n",
- _argv[-1], strerror(errno));
+ warn("%s", _argv[-1]);
ateof = 1;
continue;
}
@@ -307,8 +310,7 @@ next(argv)
for (;;) {
if (*_argv) {
if (!(freopen(*_argv, "r", stdin))) {
- (void)fprintf(stderr, "hexdump: %s: %s\n",
- *_argv, strerror(errno));
+ warn("%s", *_argv);
exitval = 1;
++_argv;
continue;
@@ -339,7 +341,7 @@ doskip(fname, statok)
if (statok) {
if (fstat(fileno(stdin), &sb))
- err("%s: %s", fname, strerror(errno));
+ err(1, "%s", fname);
if (S_ISREG(sb.st_mode) && skip >= sb.st_size) {
address += sb.st_size;
skip -= sb.st_size;
@@ -348,7 +350,7 @@ doskip(fname, statok)
}
if (S_ISREG(sb.st_mode)) {
if (fseek(stdin, skip, SEEK_SET))
- err("%s: %s", fname, strerror(errno));
+ err(1, "%s", fname);
address += skip;
skip = 0;
} else {
@@ -375,5 +377,5 @@ emalloc(size)
void
nomem()
{
- err("%s", strerror(errno));
+ err(1, NULL);
}
diff --git a/usr.bin/hexdump/hexdump.c b/usr.bin/hexdump/hexdump.c
index fec0b10..36d35a3 100644
--- a/usr.bin/hexdump/hexdump.c
+++ b/usr.bin/hexdump/hexdump.c
@@ -32,18 +32,21 @@
*/
#ifndef lint
-static char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1989, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
+#if 0
static char sccsid[] = "@(#)hexdump.c 8.1 (Berkeley) 6/6/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/types.h>
-#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -81,32 +84,3 @@ main(argc, argv)
display();
exit(exitval);
}
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-void
-#if __STDC__
-err(const char *fmt, ...)
-#else
-err(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- (void)fprintf(stderr, "hexdump: ");
- (void)vfprintf(stderr, fmt, ap);
- va_end(ap);
- (void)fprintf(stderr, "\n");
- exit(1);
- /* NOTREACHED */
-}
diff --git a/usr.bin/hexdump/hexdump.h b/usr.bin/hexdump/hexdump.h
index 82ec51d..165673a 100644
--- a/usr.bin/hexdump/hexdump.h
+++ b/usr.bin/hexdump/hexdump.h
@@ -85,7 +85,6 @@ void conv_c __P((PR *, u_char *));
void conv_u __P((PR *, u_char *));
void display __P((void));
void doskip __P((char *, int));
-void err __P((const char *, ...));
void *emalloc __P((int));
void escape __P((char *));
u_char *get __P((void));
diff --git a/usr.bin/hexdump/hexsyntax.c b/usr.bin/hexdump/hexsyntax.c
index 279a68c..ae21411 100644
--- a/usr.bin/hexdump/hexsyntax.c
+++ b/usr.bin/hexdump/hexsyntax.c
@@ -32,11 +32,16 @@
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)hexsyntax.c 8.2 (Berkeley) 5/4/95";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/types.h>
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -92,7 +97,7 @@ newsyntax(argc, argvp)
break;
case 'n':
if ((length = atoi(optarg)) < 0)
- err("%s: bad length value", optarg);
+ errx(1, "%s: bad length value", optarg);
break;
case 'o':
add("\"%07.7_Ax\n\"");
@@ -100,7 +105,7 @@ newsyntax(argc, argvp)
break;
case 's':
if ((skip = strtol(optarg, &p, 0)) < 0)
- err("%s: bad skip value", optarg);
+ errx(1, "%s: bad skip value", optarg);
switch(*p) {
case 'b':
skip *= 512;
@@ -135,7 +140,10 @@ newsyntax(argc, argvp)
void
usage()
{
- (void)fprintf(stderr,
-"hexdump: [-bcCdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\n");
+ (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
+"usage: hexdump [-bcCdovx] [-e fmt] [-f fmt_file] [-n length]",
+" [-s skip] [file ...]",
+" hd [-bcdovx] [-e fmt] [-f fmt_file] [-n length]",
+" [-s skip] [file ...]");
exit(1);
}
diff --git a/usr.bin/hexdump/odsyntax.c b/usr.bin/hexdump/odsyntax.c
index e4c4e72..5c6d3e1 100644
--- a/usr.bin/hexdump/odsyntax.c
+++ b/usr.bin/hexdump/odsyntax.c
@@ -32,12 +32,17 @@
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)odsyntax.c 8.2 (Berkeley) 5/4/95";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/types.h>
#include <ctype.h>
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -131,12 +136,10 @@ oldsyntax(argc, argvp)
case 'w':
case '?':
default:
- (void)fprintf(stderr,
- "od: od(1) has been deprecated for hexdump(1).\n");
+ warnx("od(1) has been deprecated for hexdump(1)");
if (ch != '?')
- (void)fprintf(stderr,
-"od: hexdump(1) compatibility doesn't support the -%c option%s\n",
- ch, ch == 's' ? "; see strings(1)." : ".");
+ warnx("hexdump(1) compatibility doesn't support the -%c option%s",
+ ch, ch == 's' ? "; see strings(1)" : "");
usage();
}
diff --git a/usr.bin/hexdump/parse.c b/usr.bin/hexdump/parse.c
index 99c207a..6fae728 100644
--- a/usr.bin/hexdump/parse.c
+++ b/usr.bin/hexdump/parse.c
@@ -32,12 +32,16 @@
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/types.h>
-#include <errno.h>
+#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@@ -57,10 +61,10 @@ addfile(name)
char buf[2048 + 1];
if ((fp = fopen(name, "r")) == NULL)
- err("%s: %s\n", name, strerror(errno));
+ err(1, "%s", name);
while (fgets(buf, sizeof(buf), fp)) {
if (!(p = index(buf, '\n'))) {
- (void)fprintf(stderr, "hexdump: line too long.\n");
+ warnx("line too long");
while ((ch = getchar()) != '\n' && ch != EOF);
continue;
}
@@ -391,7 +395,7 @@ isint2: switch(fu->bcnt) {
/* Only one conversion character if byte count. */
if (!(pr->flags&F_ADDRESS) && fu->bcnt && nconv++)
- err("byte count with multiple conversion characters");
+ errx(1, "byte count with multiple conversion characters");
}
/*
* If format unit byte count not specified, figure it out
@@ -483,25 +487,25 @@ void
badcnt(s)
char *s;
{
- err("%s: bad byte count", s);
+ errx(1, "%s: bad byte count", s);
}
void
badsfmt()
{
- err("%%s: requires a precision or a byte count\n");
+ errx(1, "%%s: requires a precision or a byte count");
}
void
badfmt(fmt)
char *fmt;
{
- err("\"%s\": bad format\n", fmt);
+ errx(1, "\"%s\": bad format", fmt);
}
void
badconv(ch)
char *ch;
{
- err("%%%s: bad conversion character\n", ch);
+ errx(1, "%%%s: bad conversion character", ch);
}
OpenPOWER on IntegriCloud