diff options
author | wes <wes@FreeBSD.org> | 1999-07-22 01:22:08 +0000 |
---|---|---|
committer | wes <wes@FreeBSD.org> | 1999-07-22 01:22:08 +0000 |
commit | 0d2dd20d4a50fefda45acfafe1b106d23fa2c7b7 (patch) | |
tree | 70d043a83cb1fb08ef1c5b117588003f0c427637 /usr.bin/file | |
parent | 150e7c6457f58813a0eaabce9517bafa2920b42b (diff) | |
download | FreeBSD-src-0d2dd20d4a50fefda45acfafe1b106d23fa2c7b7.zip FreeBSD-src-0d2dd20d4a50fefda45acfafe1b106d23fa2c7b7.tar.gz |
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>
Diffstat (limited to 'usr.bin/file')
-rw-r--r-- | usr.bin/file/apprentice.c | 9 | ||||
-rw-r--r-- | usr.bin/file/file.h | 4 |
2 files changed, 7 insertions, 6 deletions
diff --git a/usr.bin/file/apprentice.c b/usr.bin/file/apprentice.c index ee3ffa4..041ead0 100644 --- a/usr.bin/file/apprentice.c +++ b/usr.bin/file/apprentice.c @@ -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; diff --git a/usr.bin/file/file.h b/usr.bin/file/file.h index be326a5..d62942e 100644 --- a/usr.bin/file/file.h +++ b/usr.bin/file/file.h @@ -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 */ |