+*.lo
+*.la
.deps
.depend
.depend-done
*/
switch (is_tar(buf, nbytes)) {
case 1:
- ckfputs(iflag ? "application/x-tar" : "tar archive", stdout);
+ ckfputs((fmagic_flags & FMAGIC_FLAGS_MIME) ? "application/x-tar" : "tar archive", stdout);
return 1;
case 2:
- ckfputs(iflag ? "application/x-tar, POSIX"
+ ckfputs((fmagic_flags & FMAGIC_FLAGS_MIME) ? "application/x-tar, POSIX"
: "POSIX tar archive", stdout);
return 1;
}
}
}
- if (iflag) {
+ if ((fmagic_flags & FMAGIC_FLAGS_MIME)) {
if (subtype_mime != NULL)
ckfputs(subtype_mime, stdout);
else
/* Global command-line options */
/*@unchecked@*/
- int debug = 0; /* debugging */
-/*@unchecked@*/
- int bflag = 0; /* brief output format */
-/*@unchecked@*/
- int iflag = 0;
-/*@unchecked@*/
- int kflag = 0; /* Keep going after the first match */
-/*@unchecked@*/
- int lflag = 0; /* follow Symlinks (BSD only) */
-/*@unchecked@*/
- int sflag = 0; /* read block special files */
-/*@unchecked@*/
- int zflag = 0; /* follow (uncompress) compressed files */
-
-/*@unchecked@*/
static int nobuffer = 0; /* Do not buffer stdout */
/*@unchecked@*/ /*@null@*/
*/
int
main(int argc, char **argv)
- /*@globals debug, bflag, zflag, sflag, iflag, nobuffer, kflag,
+ /*@globals fmagic_flags, nobuffer,
default_magicfile, lineno, magicfile, mlist, optind, progname,
fileSystem, internalState @*/
- /*@modifies argv, debug, bflag, zflag, sflag, iflag, nobuffer, kflag,
+ /*@modifies argv, fmagic_flags, nobuffer,
default_magicfile, lineno, magicfile, mlist, optind, progname,
fileSystem, internalState @*/
{
/*@switchbreak@*/ break;
#endif
case 'b':
- ++bflag;
+ fmagic_flags |= FMAGIC_FLAGS_BRIEF;
/*@switchbreak@*/ break;
case 'c':
action = CHECK;
action = COMPILE;
/*@switchbreak@*/ break;
case 'd':
- ++debug;
+ fmagic_flags |= FMAGIC_FLAGS_DEBUG;
/*@switchbreak@*/ break;
case 'f':
if (!app) {
++didsomefiles;
/*@switchbreak@*/ break;
case 'i':
- iflag++;
+ fmagic_flags |= FMAGIC_FLAGS_MIME;
mime = malloc(strlen(magicfile) + sizeof(".mime"));
(void)strcpy(mime, magicfile);
(void)strcat(mime, ".mime");
magicfile = mime;
/*@switchbreak@*/ break;
case 'k':
- kflag = 1;
+ fmagic_flags |= FMAGIC_FLAGS_CONTINUE;
/*@switchbreak@*/ break;
case 'm':
magicfile = optarg;
++nobuffer;
/*@switchbreak@*/ break;
case 's':
- sflag++;
+ fmagic_flags |= FMAGIC_FLAGS_SPECIAL;
/*@switchbreak@*/ break;
case 'v':
(void) fprintf(stdout, "%s-%d.%d\n", progname,
magicfile);
return 1;
case 'z':
- zflag++;
+ fmagic_flags |= FMAGIC_FLAGS_UNCOMPRESS;
/*@switchbreak@*/ break;
#ifdef S_IFLNK
case 'L':
- ++lflag;
+ fmagic_flags |= FMAGIC_FLAGS_FOLLOW;
/*@switchbreak@*/ break;
#endif
case '?':
}
}
- if (errflg) {
+ if (errflg)
usage();
- }
if (!app) {
ret = apprentice(magicfile, action);
}
if (optind == argc) {
- if (!didsomefiles) {
+ if (!didsomefiles)
usage();
- }
- }
- else {
+ } else {
int i, wid, nw;
for (wid = 0, i = optind; i < argc; i++) {
nw = strlen(argv[i]);
muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
/*@=noeffect@*/
#endif
+
return 0;
}
/*@unchecked@*/
extern struct mlist mlist; /* list of arrays of magic entries */
-/*@-exportlocal@*/
-/*@unchecked@*/
-extern int debug; /* enable debugging? */
-/*@unchecked@*/
-extern int bflag; /* brief output format */
-/*@unchecked@*/
-extern int iflag; /* Output types as mime-types */
-/*@unchecked@*/
-extern int kflag; /* Keep going after the first match */
-/*@unchecked@*/
-extern int lflag; /* follow symbolic links? */
-/*@unchecked@*/
-extern int sflag; /* read/analyze block special files? */
-/*@unchecked@*/
-extern int zflag; /* process compressed files? */
-/*@=exportlocal@*/
+enum fmagic_e {
+ FMAGIC_FLAGS_NONE = 0,
+ FMAGIC_FLAGS_DEBUG = (1 << 0),
+ FMAGIC_FLAGS_BRIEF = (1 << 1), /*!< brief output format */
+ FMAGIC_FLAGS_MIME = (1 << 2), /*!< output as mime-types */
+ FMAGIC_FLAGS_CONTINUE = (1 << 3), /*!< continue after 1st match */
+ FMAGIC_FLAGS_FOLLOW = (1 << 4), /*!< follow symlinks? */
+ FMAGIC_FLAGS_SPECIAL = (1 << 5), /*!< analyze block devices? */
+ FMAGIC_FLAGS_UNCOMPRESS = (1 << 6) /*!< uncompress files? */
+};
+
+extern int fmagic_flags;
/*@mayexit@*/
extern int apprentice(const char *fn, int action)
FILE_RCSID("@(#)Id: fsmagic.c,v 1.36 2002/07/03 19:00:41 christos Exp ")
+int fmagic_flags = 0;
+
int
fsmagic(const char *fn, struct stat *sb)
{
* On 4.2BSD and similar systems, use lstat() to identify symlinks.
*/
#if defined(S_IFLNK) || defined(__LCLINT__)
- if (!lflag)
+ if (!(fmagic_flags & FMAGIC_FLAGS_FOLLOW))
ret = lstat(fn, sb);
else
#endif
return 1;
}
- if (iflag) {
+ if ((fmagic_flags & FMAGIC_FLAGS_MIME)) {
if ((sb->st_mode & S_IFMT) != S_IFREG) {
ckfputs("application/x-not-regular-file", stdout);
return 1;
* like ordinary files. Otherwise, just report that they
* are block special files and go on to the next file.
*/
- if (sflag)
+ if ((fmagic_flags & FMAGIC_FLAGS_SPECIAL))
break;
#ifdef HAVE_STRUCT_STAT_ST_RDEV
# ifdef dv_unit
* like ordinary files. Otherwise, just report that they
* are block special files and go on to the next file.
*/
- if (sflag)
+ if ((fmagic_flags & FMAGIC_FLAGS_SPECIAL))
break;
#ifdef HAVE_STRUCT_STAT_ST_RDEV
# ifdef dv_unit
/*@=branchstate@*/
/* Otherwise, handle it. */
- if (lflag) {
+ if ((fmagic_flags & FMAGIC_FLAGS_FOLLOW)) {
process(buf, strlen(buf));
return 1;
} else { /* just print what it points to */
* the fact that it is empty will be detected and reported correctly
* when we read the file.)
*/
- if (!sflag && sb->st_size == 0) {
- ckfputs(iflag ? "application/x-empty" : "empty", stdout);
+ if (!(fmagic_flags & FMAGIC_FLAGS_SPECIAL) && sb->st_size == 0) {
+ ckfputs((fmagic_flags & FMAGIC_FLAGS_MIME) ? "application/x-empty" : "empty", stdout);
return 1;
}
return 0;
return 'a';
/* abandon hope, all ye who remain here */
- ckfputs(iflag ? "application/octet-stream" : "data", stdout);
+ ckfputs((fmagic_flags & FMAGIC_FLAGS_MIME) ? "application/octet-stream" : "data", stdout);
return '\0';
}
inname = stdname;
}
- if (wid > 0 && !bflag)
+ if (wid > 0 && !(fmagic_flags & FMAGIC_FLAGS_BRIEF))
(void) printf("%s:%*s ", inname,
(int) (wid - strlen(inname)), "");
}
if (nbytes == 0)
- ckfputs(iflag ? "application/x-empty" : "empty", stdout);
+ ckfputs((fmagic_flags & FMAGIC_FLAGS_MIME) ? "application/x-empty" : "empty", stdout);
else {
buf[nbytes++] = '\0'; /* null-terminate it */
- match = tryit(inname, buf, nbytes, zflag);
+ match = tryit(inname, buf, nbytes, (fmagic_flags & FMAGIC_FLAGS_UNCOMPRESS));
}
#ifdef BUILTIN_ELF
}
/*@=branchstate@*/
- if (debug) {
+ if (fmagic_flags & FMAGIC_FLAGS_DEBUG) {
sm_debug(offset, (char *) p, sizeof(union VALUETYPE));
mdump(m);
}
memcpy(p, s + offset, sizeof(union VALUETYPE));
- if (debug) {
+ if (fmagic_flags & FMAGIC_FLAGS_DEBUG) {
sm_debug(offset, (char *) p, sizeof(union VALUETYPE));
mdump(m);
}
switch (m->reln) {
case 'x':
- if (debug)
+ if (fmagic_flags & FMAGIC_FLAGS_DEBUG)
(void) fprintf(stderr, "%u == *any* = 1\n", v);
matched = 1;
break;
case '!':
matched = v != l;
- if (debug)
+ if (fmagic_flags & FMAGIC_FLAGS_DEBUG)
(void) fprintf(stderr, "%u != %u = %d\n",
v, l, matched);
break;
case '=':
matched = v == l;
- if (debug)
+ if (fmagic_flags & FMAGIC_FLAGS_DEBUG)
(void) fprintf(stderr, "%u == %u = %d\n",
v, l, matched);
break;
case '>':
if (m->flag & UNSIGNED) {
matched = v > l;
- if (debug)
+ if (fmagic_flags & FMAGIC_FLAGS_DEBUG)
(void) fprintf(stderr, "%u > %u = %d\n",
v, l, matched);
}
else {
matched = (int32_t) v > (int32_t) l;
- if (debug)
+ if (fmagic_flags & FMAGIC_FLAGS_DEBUG)
(void) fprintf(stderr, "%d > %d = %d\n",
v, l, matched);
}
case '<':
if (m->flag & UNSIGNED) {
matched = v < l;
- if (debug)
+ if (fmagic_flags & FMAGIC_FLAGS_DEBUG)
(void) fprintf(stderr, "%u < %u = %d\n",
v, l, matched);
}
else {
matched = (int32_t) v < (int32_t) l;
- if (debug)
+ if (fmagic_flags & FMAGIC_FLAGS_DEBUG)
(void) fprintf(stderr, "%d < %d = %d\n",
v, l, matched);
}
case '&':
matched = (v & l) == l;
- if (debug)
+ if (fmagic_flags & FMAGIC_FLAGS_DEBUG)
(void) fprintf(stderr, "((%x & %x) == %x) = %d\n",
v, l, l, matched);
break;
case '^':
matched = (v & l) != l;
- if (debug)
+ if (fmagic_flags & FMAGIC_FLAGS_DEBUG)
(void) fprintf(stderr, "((%x & %x) != %x) = %d\n",
v, l, l, matched);
break;
}
firstline = 0;
returnval = 1;
- if (!kflag) /* don't keep searching */
+ if (!(fmagic_flags & FMAGIC_FLAGS_CONTINUE)) /* don't keep searching */
return 1;
}
return returnval; /* This is hit if -k is set or there is no match */