diff options
Diffstat (limited to 'usr.bin/file')
-rw-r--r-- | usr.bin/file/apprentice.c | 29 | ||||
-rw-r--r-- | usr.bin/file/ascmagic.c | 5 | ||||
-rw-r--r-- | usr.bin/file/compress.c | 18 | ||||
-rw-r--r-- | usr.bin/file/file.c | 32 | ||||
-rw-r--r-- | usr.bin/file/file.h | 4 | ||||
-rw-r--r-- | usr.bin/file/fsmagic.c | 7 | ||||
-rw-r--r-- | usr.bin/file/print.c | 67 | ||||
-rw-r--r-- | usr.bin/file/readelf.c | 18 | ||||
-rw-r--r-- | usr.bin/file/softmagic.c | 21 |
9 files changed, 67 insertions, 134 deletions
diff --git a/usr.bin/file/apprentice.c b/usr.bin/file/apprentice.c index 8a5ccbec20f..6ec2908cefd 100644 --- a/usr.bin/file/apprentice.c +++ b/usr.bin/file/apprentice.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apprentice.c,v 1.4 1997/02/09 23:58:16 millert Exp $ */ +/* $OpenBSD: apprentice.c,v 1.5 1998/07/10 15:05:13 mickey Exp $ */ /* * apprentice - make one pass through /etc/magic, learning its secrets. @@ -32,10 +32,11 @@ #include <string.h> #include <ctype.h> #include <errno.h> +#include <err.h> #include "file.h" #ifndef lint -static char *moduleid = "$OpenBSD: apprentice.c,v 1.4 1997/02/09 23:58:16 millert Exp $"; +static char *moduleid = "$OpenBSD: apprentice.c,v 1.5 1998/07/10 15:05:13 mickey Exp $"; #endif /* lint */ #define EATAB {while (isascii((unsigned char) *l) && \ @@ -66,7 +67,7 @@ int check; /* non-zero? checking-only run. */ magic = (struct magic *) calloc(sizeof(struct magic), maxmagic); mfn = malloc(strlen(fn)+1); if (magic == NULL || mfn == NULL) { - (void) fprintf(stderr, "%s: Out of memory.\n", progname); + warn("malloc"); if (check) return -1; else @@ -84,8 +85,7 @@ int check; /* non-zero? checking-only run. */ fn = p; } if (errs == -1) - (void) fprintf(stderr, "%s: couldn't find any magic files!\n", - progname); + warnx("couldn't find any magic files!"); if (!check && errs) exit(1); @@ -107,9 +107,7 @@ int check; /* non-zero? checking-only run. */ f = fopen(fn, "r"); if (f==NULL) { if (errno != ENOENT) - (void) fprintf(stderr, - "%s: can't read magic file %s (%s)\n", - progname, fn, strerror(errno)); + warn(fn); return -1; } @@ -165,8 +163,7 @@ uint32 v; case STRING: break; default: - magwarn("can't happen: m->type=%d\n", - m->type); + warnx("can't happen: m->type=%d\n", m->type); return -1; } return v; @@ -190,7 +187,7 @@ int *ndx, check; if ((magic = (struct magic *) realloc(magic, sizeof(struct magic) * maxmagic)) == NULL) { - (void) fprintf(stderr, "%s: Out of memory.\n", progname); + warn("malloc"); if (check) return -1; else @@ -219,7 +216,7 @@ int *ndx, check; /* get offset, then skip over it */ m->offset = (int) strtoul(l,&t,0); if (l == t) - magwarn("offset %s invalid", l); + warnx("offset %s invalid", l); l = t; if (m->flag & INDIR) { @@ -243,7 +240,7 @@ int *ndx, check; m->in.type = BYTE; break; default: - magwarn("indirect offset type %c invalid", *l); + warnx("indirect offset type %c invalid", *l); break; } l++; @@ -257,7 +254,7 @@ int *ndx, check; else t = l; if (*t++ != ')') - magwarn("missing ')' in indirect offset"); + warnx("missing ')' in indirect offset"); l = t; } @@ -318,7 +315,7 @@ int *ndx, check; m->type = LEDATE; l += NLEDATE; } else { - magwarn("type %s invalid", l); + warnx("type %s invalid", l); return -1; } /* New-style anding: "0 byte&0x80 =0x80 dynamically linked" */ @@ -364,7 +361,7 @@ int *ndx, check; /* * TODO finish this macro and start using it! * #define offsetcheck {if (offset > HOWMANY-1) - * magwarn("offset too big"); } + * warnx("offset too big"); } */ /* diff --git a/usr.bin/file/ascmagic.c b/usr.bin/file/ascmagic.c index 9caa50eff7b..73958d23773 100644 --- a/usr.bin/file/ascmagic.c +++ b/usr.bin/file/ascmagic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ascmagic.c,v 1.3 1997/02/09 23:58:18 millert Exp $ */ +/* $OpenBSD: ascmagic.c,v 1.4 1998/07/10 15:05:15 mickey Exp $ */ /* * ASCII magic -- file types that we know based on keywords @@ -33,11 +33,12 @@ #include <ctype.h> #include <stdlib.h> #include <unistd.h> +#include <err.h> #include "file.h" #include "names.h" #ifndef lint -static char *moduleid = "$OpenBSD: ascmagic.c,v 1.3 1997/02/09 23:58:18 millert Exp $"; +static char *moduleid = "$OpenBSD: ascmagic.c,v 1.4 1998/07/10 15:05:15 mickey Exp $"; #endif /* lint */ /* an optimisation over plain strcmp() */ diff --git a/usr.bin/file/compress.c b/usr.bin/file/compress.c index bde1ff4a9d7..7c6ef4d42a2 100644 --- a/usr.bin/file/compress.c +++ b/usr.bin/file/compress.c @@ -1,4 +1,4 @@ -/* $OpenBSD: compress.c,v 1.3 1997/02/09 23:58:19 millert Exp $ */ +/* $OpenBSD: compress.c,v 1.4 1998/07/10 15:05:19 mickey Exp $ */ /* * compress routines: @@ -7,11 +7,12 @@ * uncompress(method, old, n, newch) - uncompress old into new, * using method, return sizeof new */ +#include <sys/wait.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> -#include <sys/wait.h> +#include <err.h> #include "file.h" @@ -74,7 +75,7 @@ int n; int fdin[2], fdout[2]; if (pipe(fdin) == -1 || pipe(fdout) == -1) { - error("cannot create pipe (%s).\n", strerror(errno)); + err(1, "cannot create pipe"); /*NOTREACHED*/ } switch (fork()) { @@ -92,28 +93,27 @@ int n; (void) close(2); execvp(compr[method].argv[0], compr[method].argv); - error("could not execute `%s' (%s).\n", - compr[method].argv[0], strerror(errno)); + err(1, "could not execute `%s'", compr[method].argv[0]); /*NOTREACHED*/ case -1: - error("could not fork (%s).\n", strerror(errno)); + err(1, "could not fork"); /*NOTREACHED*/ default: /* parent */ (void) close(fdin[0]); (void) close(fdout[1]); if (write(fdin[1], old, n) != n) { - error("write failed (%s).\n", strerror(errno)); + err(1, "write failed"); /*NOTREACHED*/ } (void) close(fdin[1]); if ((*newch = (unsigned char *) malloc(n)) == NULL) { - error("out of memory.\n"); + err(1, "malloc"); /*NOTREACHED*/ } if ((n = read(fdout[0], *newch, n)) <= 0) { free(*newch); - error("read failed (%s).\n", strerror(errno)); + err(1, "read failed"); /*NOTREACHED*/ } (void) close(fdout[0]); diff --git a/usr.bin/file/file.c b/usr.bin/file/file.c index 95eeb944ca7..06b10deaf54 100644 --- a/usr.bin/file/file.c +++ b/usr.bin/file/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.5 1997/02/09 23:58:22 millert Exp $ */ +/* $OpenBSD: file.c,v 1.6 1998/07/10 15:05:20 mickey Exp $ */ /* * file - find type of a file or files - main program. @@ -27,7 +27,7 @@ * 4. This notice may not be removed or altered. */ #ifndef lint -static char *moduleid = "$OpenBSD: file.c,v 1.5 1997/02/09 23:58:22 millert Exp $"; +static char *moduleid = "$OpenBSD: file.c,v 1.6 1998/07/10 15:05:20 mickey Exp $"; #endif /* lint */ #include <stdio.h> @@ -47,6 +47,7 @@ static char *moduleid = "$OpenBSD: file.c,v 1.5 1997/02/09 23:58:22 millert Exp # endif #endif #include <unistd.h> /* for read() */ +#include <err.h> #include <netinet/in.h> /* for byte swapping */ @@ -75,7 +76,6 @@ struct magic *magic; /* array of magic entries */ char *magicfile; /* where magic be found */ -char *progname; /* used throughout */ int lineno; /* line number in the magic file */ @@ -95,11 +95,7 @@ char *argv[]; { int c; int check = 0, didsomefiles = 0, errflg = 0, ret = 0, app = 0; - - if ((progname = strrchr(argv[0], '/')) != NULL) - progname++; - else - progname = argv[0]; + extern char *__progname; if (!(magicfile = getenv("MAGIC"))) magicfile = MAGIC; @@ -107,7 +103,7 @@ char *argv[]; while ((c = getopt(argc, argv, "vcdf:Lm:z")) != -1) switch (c) { case 'v': - (void) fprintf(stdout, "%s-%d.%d\n", progname, + (void) printf("%s-%d.%d\n", __progname, FILE_VERSION_MAJOR, patchlevel); return 1; case 'c': @@ -144,7 +140,7 @@ char *argv[]; } if (errflg) { - (void) fprintf(stderr, USAGE, progname); + (void) fprintf(stderr, USAGE, __progname); exit(2); } @@ -156,12 +152,9 @@ char *argv[]; } if (optind == argc) { - if (!didsomefiles) { - (void)fprintf(stderr, USAGE, progname); - exit(2); - } - } - else { + if (!didsomefiles) + err(2, USAGE, __progname); + } else { int i, wid, nw; for (wid = 0, i = optind; i < argc; i++) { nw = strlen(argv[i]); @@ -192,7 +185,7 @@ char *fn; wid = 1; } else { if ((f = fopen(fn, "r")) == NULL) { - error("Cannot open `%s' (%s).\n", fn, strerror(errno)); + err(1, "Cannot open `%s'", fn); /*NOTREACHED*/ } @@ -296,8 +289,7 @@ int wid; if (strcmp("-", inname) == 0) { if (fstat(0, &sb)<0) { - error("cannot fstat `%s' (%s).\n", stdname, - strerror(errno)); + err(1, "cannot fstat `%s'", stdname); /*NOTREACHED*/ } inname = stdname; @@ -331,7 +323,7 @@ int wid; * try looking at the first HOWMANY bytes */ if ((nbytes = read(fd, (char *)buf, HOWMANY)) == -1) { - error("read failed (%s).\n", strerror(errno)); + err(1, "read failed"); /*NOTREACHED*/ } diff --git a/usr.bin/file/file.h b/usr.bin/file/file.h index b09a8eccb10..4f224627cf0 100644 --- a/usr.bin/file/file.h +++ b/usr.bin/file/file.h @@ -1,4 +1,4 @@ -/* $OpenBSD: file.h,v 1.4 1997/07/25 21:05:26 mickey Exp $ */ +/* $OpenBSD: file.h,v 1.5 1998/07/10 15:05:21 mickey Exp $ */ /* * file.h - definitions for file(1) program @@ -91,13 +91,11 @@ struct magic { extern int apprentice __P((char *, int)); extern int ascmagic __P((unsigned char *, int)); -extern void error __P((const char *, ...)); extern void ckfputs __P((const char *, FILE *)); struct stat; extern int fsmagic __P((const char *, struct stat *)); extern int is_compress __P((const unsigned char *, int *)); extern int is_tar __P((unsigned char *, int)); -extern void magwarn __P((const char *, ...)); extern void mdump __P((struct magic *)); extern void process __P((const char *, int)); extern void showstr __P((FILE *, const char *, int)); diff --git a/usr.bin/file/fsmagic.c b/usr.bin/file/fsmagic.c index f5ba6ee0b4e..706664485a3 100644 --- a/usr.bin/file/fsmagic.c +++ b/usr.bin/file/fsmagic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fsmagic.c,v 1.3 1997/02/09 23:58:24 millert Exp $ */ +/* $OpenBSD: fsmagic.c,v 1.4 1998/07/10 15:05:22 mickey Exp $ */ /* * fsmagic - magic based on filesystem info - directory, special files, etc. @@ -33,6 +33,7 @@ #include <sys/stat.h> #include <unistd.h> #include <stdlib.h> +#include <err.h> #ifndef major # if defined(__SVR4) || defined(_SVR4_SOURCE) # include <sys/mkdev.h> @@ -52,7 +53,7 @@ #include "file.h" #ifndef lint -static char *moduleid = "$OpenBSD: fsmagic.c,v 1.3 1997/02/09 23:58:24 millert Exp $"; +static char *moduleid = "$OpenBSD: fsmagic.c,v 1.4 1998/07/10 15:05:22 mickey Exp $"; #endif /* lint */ int @@ -166,7 +167,7 @@ struct stat *sb; case S_IFREG: break; default: - error("invalid mode 0%o.\n", sb->st_mode); + errx(1, "invalid mode 0%o", sb->st_mode); /*NOTREACHED*/ } diff --git a/usr.bin/file/print.c b/usr.bin/file/print.c index 7f707c4bf01..0bc8c5f1fe2 100644 --- a/usr.bin/file/print.c +++ b/usr.bin/file/print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print.c,v 1.5 1997/08/24 18:33:12 millert Exp $ */ +/* $OpenBSD: print.c,v 1.6 1998/07/10 15:05:25 mickey Exp $ */ /* * print.c - debugging printout routines @@ -38,10 +38,11 @@ #include <stdlib.h> #include <unistd.h> #include <time.h> +#include <err.h> #include "file.h" #ifndef lint -static char *moduleid = "$OpenBSD: print.c,v 1.5 1997/08/24 18:33:12 millert Exp $"; +static char *moduleid = "$OpenBSD: print.c,v 1.6 1998/07/10 15:05:25 mickey Exp $"; #endif /* lint */ #define SZOF(a) (sizeof(a) / sizeof(a[0])) @@ -118,7 +119,7 @@ ckfputs(str, fil) FILE *fil; { if (fputs(str,fil) == EOF) - error("write failed.\n"); + err(1, "write failed"); } /*VARARGS*/ @@ -142,64 +143,6 @@ ckfprintf(va_alist) #endif (void) vfprintf(f, fmt, va); if (ferror(f)) - error("write failed.\n"); + err(1, "write failed"); va_end(va); } - -/* - * error - print best error message possible and exit - */ -/*VARARGS*/ -void -#ifdef __STDC__ -error(const char *f, ...) -#else -error(va_alist) - va_dcl -#endif -{ - va_list va; -#ifdef __STDC__ - va_start(va, f); -#else - const char *f; - va_start(va); - f = va_arg(va, const char *); -#endif - /* cuz we use stdout for most, stderr here */ - (void) fflush(stdout); - - if (progname != NULL) - (void) fprintf(stderr, "%s: ", progname); - (void) vfprintf(stderr, f, va); - va_end(va); - exit(1); -} - -/*VARARGS*/ -void -#ifdef __STDC__ -magwarn(const char *f, ...) -#else -magwarn(va_alist) - va_dcl -#endif -{ - va_list va; -#ifdef __STDC__ - va_start(va, f); -#else - const char *f; - va_start(va); - f = va_arg(va, const char *); -#endif - /* cuz we use stdout for most, stderr here */ - (void) fflush(stdout); - - if (progname != NULL) - (void) fprintf(stderr, "%s: %s, %d: ", - progname, magicfile, lineno); - (void) vfprintf(stderr, f, va); - va_end(va); - fputc('\n', stderr); -} diff --git a/usr.bin/file/readelf.c b/usr.bin/file/readelf.c index 7f4f97bb4bd..d6ee631de6d 100644 --- a/usr.bin/file/readelf.c +++ b/usr.bin/file/readelf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: readelf.c,v 1.1 1997/02/09 23:58:33 millert Exp $ */ +/* $OpenBSD: readelf.c,v 1.2 1998/07/10 15:05:26 mickey Exp $ */ #ifdef BUILTIN_ELF #include <sys/types.h> @@ -31,11 +31,11 @@ doshn(fd, off, num, size, buf) Elf32_Shdr *sh = (Elf32_Shdr *) buf; if (lseek(fd, off, SEEK_SET) == -1) - error("lseek failed (%s).\n", strerror(errno)); + err(1, "lseek failed"); for ( ; num; num--) { if (read(fd, buf, size) == -1) - error("read failed (%s).\n", strerror(errno)); + err(1, "read failed"); if (sh->sh_type == SHT_SYMTAB) { (void) printf (", not stripped"); return; @@ -61,11 +61,11 @@ dophn_exec(fd, off, num, size, buf) Elf32_Phdr *ph = (Elf32_Phdr *) buf; if (lseek(fd, off, SEEK_SET) == -1) - error("lseek failed (%s).\n", strerror(errno)); + err(1, "lseek failed"); for ( ; num; num--) { if (read(fd, buf, size) == -1) - error("read failed (%s).\n", strerror(errno)); + err(1, "read failed"); if (ph->p_type == PT_INTERP) { /* * Has an interpreter - must be a dynamically-linked @@ -122,17 +122,17 @@ dophn_core(fd, off, num, size, buf) for ( ; num; num--) { if (lseek(fd, off, SEEK_SET) == -1) - error("lseek failed (%s).\n", strerror(errno)); + err(1, "lseek failed"); if (read(fd, buf, size) == -1) - error("read failed (%s).\n", strerror(errno)); + err(1, "read failed"); off += size; if (ph->p_type != PT_NOTE) continue; if (lseek(fd, ph->p_offset, SEEK_SET) == -1) - error("lseek failed (%s).\n", strerror(errno)); + err(1, "lseek failed"); bufsize = read(fd, nbuf, BUFSIZ); if (bufsize == -1) - error("read failed (%s).\n", strerror(errno)); + err(1, "read failed"); offset = 0; for (;;) { if (offset >= bufsize) diff --git a/usr.bin/file/softmagic.c b/usr.bin/file/softmagic.c index a3e2f109620..40bbd124b70 100644 --- a/usr.bin/file/softmagic.c +++ b/usr.bin/file/softmagic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softmagic.c,v 1.3 1997/02/09 23:58:36 millert Exp $ */ +/* $OpenBSD: softmagic.c,v 1.4 1998/07/10 15:05:27 mickey Exp $ */ /* * softmagic - interpret variable magic from /etc/magic @@ -27,16 +27,17 @@ * 4. This notice may not be removed or altered. */ +#include <sys/types.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> -#include <sys/types.h> +#include <err.h> #include "file.h" #ifndef lint -static char *moduleid = "$OpenBSD: softmagic.c,v 1.3 1997/02/09 23:58:36 millert Exp $"; +static char *moduleid = "$OpenBSD: softmagic.c,v 1.4 1998/07/10 15:05:27 mickey Exp $"; #endif /* lint */ static int match __P((unsigned char *, int)); @@ -106,7 +107,7 @@ int nbytes; if (tmpoff == NULL) if ((tmpoff = (int32 *) malloc(tmplen = 20)) == NULL) - error("out of memory\n"); + err(1, "malloc"); for (magindex = 0; magindex < nmagic; magindex++) { /* if main entry matches, print it... */ @@ -133,7 +134,7 @@ int nbytes; if (++cont_level >= tmplen) if ((tmpoff = (int32 *) realloc(tmpoff, tmplen += 20)) == NULL) - error("out of memory\n"); + err(1, "malloc"); while (magic[magindex+1].cont_level != 0 && ++magindex < nmagic) { if (cont_level >= magic[magindex].cont_level) { @@ -178,7 +179,7 @@ int nbytes; if ((tmpoff = (int32 *) realloc(tmpoff, tmplen += 20)) == NULL) - error("out of memory\n"); + err(1, "malloc"); } if (magic[magindex].flag & ADD) { magic[magindex].offset = oldoff; @@ -253,7 +254,7 @@ struct magic *m; break; default: - error("invalid m->type (%d) in mprint().\n", m->type); + errx(1, "invalid m->type (%d) in mprint().", m->type); /*NOTREACHED*/ } return(t); @@ -300,7 +301,7 @@ struct magic *m; ((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0])); return 1; default: - error("invalid type %d in mconvert().\n", m->type); + errx(1, "invalid type %d in mconvert().", m->type); return 0; } } @@ -433,7 +434,7 @@ struct magic *m; } break; default: - error("invalid type %d in mcheck().\n", m->type); + errx(1, "invalid type %d in mcheck().", m->type); return 0;/*NOTREACHED*/ } @@ -506,7 +507,7 @@ struct magic *m; default: matched = 0; - error("mcheck: can't happen: invalid relation %d.\n", m->reln); + errx(1, "mcheck: can't happen: invalid relation %d.", m->reln); break;/*NOTREACHED*/ } |