Vastly improve the speed of the file command by making
the expected size of the magic(5) database agree with the real world. Also, improve the behavior of the realloc mechanism when the magic database does exceed expectations. Reviewed by: Peter Jeremy, Matt Dillon Obtained from: Peter Edwards <peter.edwards@isocor.ie>
This commit is contained in:
parent
9865bd5167
commit
1f20fb8802
@ -27,7 +27,7 @@
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
"$Id: apprentice.c,v 1.7 1998/01/28 07:36:21 charnier Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <ctype.h>
|
||||
@ -50,6 +50,7 @@ static int parse __P((char *, int *, int));
|
||||
static void eatsize __P((char **));
|
||||
|
||||
static int maxmagic = 0;
|
||||
static int alloc_incr = 256;
|
||||
|
||||
static int apprentice_1 __P((char *, int));
|
||||
|
||||
@ -180,9 +181,8 @@ int *ndx, check;
|
||||
struct magic *m;
|
||||
char *t, *s;
|
||||
|
||||
#define ALLOC_INCR 20
|
||||
if (nd+1 >= maxmagic){
|
||||
maxmagic += ALLOC_INCR;
|
||||
maxmagic += alloc_incr;
|
||||
if ((magic = (struct magic *) realloc(magic,
|
||||
sizeof(struct magic) *
|
||||
maxmagic)) == NULL) {
|
||||
@ -192,7 +192,8 @@ int *ndx, check;
|
||||
else
|
||||
exit(1);
|
||||
}
|
||||
memset(&magic[*ndx], 0, sizeof(struct magic) * ALLOC_INCR);
|
||||
memset(&magic[*ndx], 0, sizeof(struct magic) * alloc_incr);
|
||||
alloc_incr *= 2;
|
||||
}
|
||||
m = &magic[*ndx];
|
||||
m->flag = 0;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* file.h - definitions for file(1) program
|
||||
* @(#)$Id: file.h,v 1.7 1997/03/18 19:37:18 mpp Exp $
|
||||
* @(#)$Id: file.h,v 1.8 1998/01/28 07:36:23 charnier Exp $
|
||||
*
|
||||
* Copyright (c) Ian F. Darwin, 1987.
|
||||
* Written by Ian F. Darwin.
|
||||
@ -35,7 +35,7 @@ typedef unsigned int uint32;
|
||||
#ifndef HOWMANY
|
||||
# define HOWMANY 8192 /* how much of the file to look at */
|
||||
#endif
|
||||
#define MAXMAGIS 1000 /* max entries in /etc/magic */
|
||||
#define MAXMAGIS 5000 /* max entries in /etc/magic */
|
||||
#define MAXDESC 50 /* max leng of text description */
|
||||
#define MAXstring 32 /* max leng of "string" types */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user