Fix magic processing

This commit is contained in:
Michiel Broek 2002-05-10 18:33:23 +00:00
parent 0f2277e9b9
commit cb7b34b7de

View File

@ -102,12 +102,14 @@ int GetMagicRec(int Typ, int First)
{ {
int Eof = FALSE, DoMagic = TRUE; int Eof = FALSE, DoMagic = TRUE;
int i; int i;
char *temp, *Magic, *p, *q, mask[256]; char *temp, *p, *q, mask[256];
FILE *FeM; FILE *FeM;
if (First) if (First)
MagicNr = 0; MagicNr = 0;
Syslog('f', "GetMagicRec(%d, %s), MagicNr = %d", Typ, First ? "true":"false", MagicNr);
temp = calloc(PATH_MAX, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/etc/magic.data", getenv("MBSE_ROOT")); sprintf(temp, "%s/etc/magic.data", getenv("MBSE_ROOT"));
if ((FeM = fopen(temp, "r")) == NULL) { if ((FeM = fopen(temp, "r")) == NULL) {
@ -132,9 +134,8 @@ int GetMagicRec(int Typ, int First)
if ((magic.Active) && (magic.Attrib == Typ) && (strcasecmp(magic.From, TIC.TicIn.Area) == 0)) { if ((magic.Active) && (magic.Attrib == Typ) && (strcasecmp(magic.From, TIC.TicIn.Area) == 0)) {
// p = tl(magic.Mask); memset(&mask, 0, sizeof(mask));
Magic = xstrcpy(magic.Mask); p = magic.Mask;
p = tl(Magic);
q = mask; q = mask;
*q++ = '^'; *q++ = '^';
while ((*p) && (q < (mask + sizeof(mask) - 4))) { while ((*p) && (q < (mask + sizeof(mask) - 4))) {
@ -152,7 +153,7 @@ int GetMagicRec(int Typ, int First)
} }
*q++ = '$'; *q++ = '$';
*q = '\0'; *q = '\0';
Syslog('f', "Magic mask \"%s\" -> \"%s\"", MBSE_SS(Magic), MBSE_SS(mask)); Syslog('f', "Magic mask \"%s\" -> \"%s\"", MBSE_SS(magic.Mask), MBSE_SS(mask));
if ((re_comp(mask)) == NULL) { if ((re_comp(mask)) == NULL) {
if (re_exec(TIC.NewName)) if (re_exec(TIC.NewName))
Syslog('f', "Should matched using regexp"); Syslog('f', "Should matched using regexp");
@ -161,7 +162,6 @@ int GetMagicRec(int Typ, int First)
} else { } else {
Syslog('f', "re_comp() failed"); Syslog('f', "re_comp() failed");
} }
free(Magic);
/* /*
* Comparing of the filename must be done in * Comparing of the filename must be done in