On Oct 24, 12:43pm, [EMAIL PROTECTED] (Jim Studt) wrote: -- Subject: Re: libmagic1: proper way to use magic_load?
| I am just the bug chaser here and don't use the library, but... | | As I understand it, the format of the magic files themselves has | changed making the .mime file superfluous. The mime type information | is now included in the "normal" magic file. I don't think a program | has to do anything special, but old style two file magic/mime pairs | will have to be changed to the new style. Does this fix the issue? christos Index: apprentice.c =================================================================== RCS file: /p/file/cvsroot/file/src/apprentice.c,v retrieving revision 1.142 diff -u -u -r1.142 apprentice.c --- apprentice.c 18 Oct 2008 20:47:48 -0000 1.142 +++ apprentice.c 24 Oct 2008 20:30:02 -0000 @@ -106,7 +106,7 @@ private uint16_t swap2(uint16_t); private uint32_t swap4(uint32_t); private uint64_t swap8(uint64_t); -private void mkdbname(const char *, char **, int); +private char *mkdbname(struct magic_set *ms, const char *, int); private int apprentice_map(struct magic_set *, struct magic **, uint32_t *, const char *); private int apprentice_compile(struct magic_set *, struct magic **, uint32_t *, @@ -2046,7 +2046,7 @@ char *dbname = NULL; void *mm = NULL; - mkdbname(fn, &dbname, 0); + dbname = mkdbname(ms, fn, 0); if (dbname == NULL) goto error2; @@ -2143,7 +2143,7 @@ char *dbname; int rv = -1; - mkdbname(fn, &dbname, 1); + dbname = mkdbname(ms, fn, 1); if (dbname == NULL) goto out; @@ -2181,24 +2181,46 @@ /* * make a dbname */ -private void -mkdbname(const char *fn, char **buf, int strip) +private char * +mkdbname(struct magic_set *ms, const char *fn, int strip) { - const char *p; + const char *p, *q; + if (strip) { if ((p = strrchr(fn, '/')) != NULL) fn = ++p; } - if ((p = strstr(fn, ext)) != NULL && p[sizeof(ext) - 1] == '\0') - *buf = strdup(fn); - else - (void)asprintf(buf, "%s%s", fn, ext); + /* Goto the end of the string */ + for (q = fn; *q; q++) + continue; - if (buf && *buf && strlen(*buf) > MAXPATHLEN) { - free(*buf); - *buf = NULL; - } + /* Look for .mgc */ + for (p = ext + sizeof(ext) - 1; p >= ext && q >= fn; p--, q--) + if (*p != *q) + break; + + /* Did not find .mgc, restore q */ + if (p >= ext) + while (*q) + q++; + + q++; + /* Compatibility with old code that looked in .mime */ + if (ms->flags & MAGIC_MIME) { + asprintf(&buf, "%.*s.mime%s", (int)(q - fn), fn, ext); + if (access(buf, R_OK) != -1) { + ms->flags &= MAGIC_MIME_TYPE; + return buf; + } + free(buf); + } + asprintf(&buf, "%.*s%s", (int)(q - fn), fn, ext); + + /* Compatibility with old code that looked in .mime */ + if (strstr(p, ".mime") != NULL) + ms->flags &= MAGIC_MIME_TYPE; + return buf; } /* -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]