version 1.4, 1997/02/09 23:58:16 |
version 1.5, 1998/07/10 15:05:13 |
|
|
#include <string.h> |
#include <string.h> |
#include <ctype.h> |
#include <ctype.h> |
#include <errno.h> |
#include <errno.h> |
|
#include <err.h> |
#include "file.h" |
#include "file.h" |
|
|
#ifndef lint |
#ifndef lint |
|
|
magic = (struct magic *) calloc(sizeof(struct magic), maxmagic); |
magic = (struct magic *) calloc(sizeof(struct magic), maxmagic); |
mfn = malloc(strlen(fn)+1); |
mfn = malloc(strlen(fn)+1); |
if (magic == NULL || mfn == NULL) { |
if (magic == NULL || mfn == NULL) { |
(void) fprintf(stderr, "%s: Out of memory.\n", progname); |
warn("malloc"); |
if (check) |
if (check) |
return -1; |
return -1; |
else |
else |
|
|
fn = p; |
fn = p; |
} |
} |
if (errs == -1) |
if (errs == -1) |
(void) fprintf(stderr, "%s: couldn't find any magic files!\n", |
warnx("couldn't find any magic files!"); |
progname); |
|
if (!check && errs) |
if (!check && errs) |
exit(1); |
exit(1); |
|
|
|
|
f = fopen(fn, "r"); |
f = fopen(fn, "r"); |
if (f==NULL) { |
if (f==NULL) { |
if (errno != ENOENT) |
if (errno != ENOENT) |
(void) fprintf(stderr, |
warn(fn); |
"%s: can't read magic file %s (%s)\n", |
|
progname, fn, strerror(errno)); |
|
return -1; |
return -1; |
} |
} |
|
|
|
|
case STRING: |
case STRING: |
break; |
break; |
default: |
default: |
magwarn("can't happen: m->type=%d\n", |
warnx("can't happen: m->type=%d\n", m->type); |
m->type); |
|
return -1; |
return -1; |
} |
} |
return v; |
return v; |
|
|
if ((magic = (struct magic *) realloc(magic, |
if ((magic = (struct magic *) realloc(magic, |
sizeof(struct magic) * |
sizeof(struct magic) * |
maxmagic)) == NULL) { |
maxmagic)) == NULL) { |
(void) fprintf(stderr, "%s: Out of memory.\n", progname); |
warn("malloc"); |
if (check) |
if (check) |
return -1; |
return -1; |
else |
else |
|
|
/* get offset, then skip over it */ |
/* get offset, then skip over it */ |
m->offset = (int) strtoul(l,&t,0); |
m->offset = (int) strtoul(l,&t,0); |
if (l == t) |
if (l == t) |
magwarn("offset %s invalid", l); |
warnx("offset %s invalid", l); |
l = t; |
l = t; |
|
|
if (m->flag & INDIR) { |
if (m->flag & INDIR) { |
|
|
m->in.type = BYTE; |
m->in.type = BYTE; |
break; |
break; |
default: |
default: |
magwarn("indirect offset type %c invalid", *l); |
warnx("indirect offset type %c invalid", *l); |
break; |
break; |
} |
} |
l++; |
l++; |
|
|
else |
else |
t = l; |
t = l; |
if (*t++ != ')') |
if (*t++ != ')') |
magwarn("missing ')' in indirect offset"); |
warnx("missing ')' in indirect offset"); |
l = t; |
l = t; |
} |
} |
|
|
|
|
m->type = LEDATE; |
m->type = LEDATE; |
l += NLEDATE; |
l += NLEDATE; |
} else { |
} else { |
magwarn("type %s invalid", l); |
warnx("type %s invalid", l); |
return -1; |
return -1; |
} |
} |
/* New-style anding: "0 byte&0x80 =0x80 dynamically linked" */ |
/* New-style anding: "0 byte&0x80 =0x80 dynamically linked" */ |
|
|
/* |
/* |
* TODO finish this macro and start using it! |
* TODO finish this macro and start using it! |
* #define offsetcheck {if (offset > HOWMANY-1) |
* #define offsetcheck {if (offset > HOWMANY-1) |
* magwarn("offset too big"); } |
* warnx("offset too big"); } |
*/ |
*/ |
|
|
/* |
/* |