#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$File: file.c,v 1.108 2007/03/12 15:43:21 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.109 2007/03/15 14:50:34 christos Exp $")
#endif /* lint */
char *home, *usermagic;
struct stat sb;
static const char hmagic[] = "/.magic";
-#define OPTSTRING "bcCde:f:F:hikLm:nNprsvz0"
+#define OPTSTRING "bcCde:f:F:hikLm:nNprstvz0"
#ifdef HAVE_GETOPT_LONG
int longindex;
static const struct option long_options[] =
{"special-files", 0, 0, 's'},
{"compile", 0, 0, 'C'},
{"print0", 0, 0, '0'},
+ {"timing", 0, 0, 't'},
{0, 0, 0, 0},
};
#endif
case 's':
flags |= MAGIC_DEVICES;
break;
+ case 't':
+ flags |= MAGIC_TIMING;
+ break;
case 'v':
(void)fprintf(stdout, "%s-%d.%.2d\n", progname,
FILE_VERSION_MAJOR, patchlevel);
" -r, --raw don't translate unprintable chars to \\ooo\n"
" -s, --special-files treat special (block/char devices) files as\n"
" ordinary ones\n"
+" -t, --timing print debug timing info\n"
" --help display this help and exit\n"
" --version output version information and exit\n"
+"or\n"
+" -C, --compile compile file specified by -m\n"
);
exit(0);
}
#define MAGIC_PRESERVE_ATIME 0x000080 /* Restore access time on exit */
#define MAGIC_RAW 0x000100 /* Don't translate unprintable chars */
#define MAGIC_ERROR 0x000200 /* Handle ENOENT etc as real errors */
+#define MAGIC_TIMING 0x000400 /* Print timing info for each entry */
#define MAGIC_NO_CHECK_COMPRESS 0x001000 /* Don't check for compressed files */
#define MAGIC_NO_CHECK_TAR 0x002000 /* Don't check for tar files */
#define MAGIC_NO_CHECK_SOFT 0x004000 /* Don't check magic entries */
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.96 2007/03/05 02:41:29 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.97 2007/03/25 03:13:47 christos Exp $")
#endif /* lint */
private int match(struct magic_set *, struct magic *, uint32_t,
int returnval = 0; /* if a match is found it is set to 1*/
int firstline = 1; /* a flag to print X\n X\n- X */
int printed_something = 0;
+ struct timeval starttv, curtv;
if (file_check_mem(ms, cont_level) == -1)
return -1;
+ starttv.tv_sec = 0;
for (magindex = 0; magindex < nmagic; magindex++) {
int flush;
+ if (ms->flags & MAGIC_TIMING) {
+ (void)gettimeofday(&curtv, NULL);
+ if (starttv.tv_sec == 0)
+ starttv = curtv;
+ else {
+ struct timeval diff;
+ timersub(&curtv, &starttv, &diff);
+ starttv = curtv;
+ (void)fprintf(stderr, "Took %ld.%ld\n",
+ (long)diff.tv_sec, (long)diff.tv_usec);
+ }
+ }
ms->offset = magic[magindex].offset;
ms->line = magic[magindex].lineno;
}
else {
regmatch_t pmatch[1];
+#undef REG_STARTEND
#ifndef REG_STARTEND
#define REG_STARTEND 0
size_t l = ms->search.s_len - 1;