Gratuitous name changes from file-4.02.
authorjbj <devnull@localhost>
Tue, 15 Apr 2003 15:03:49 +0000 (15:03 +0000)
committerjbj <devnull@localhost>
Tue, 15 Apr 2003 15:03:49 +0000 (15:03 +0000)
CVS patchset: 6743
CVS date: 2003/04/15 15:03:49

file/apprentice.c
file/ascmagic.c
file/compress.c
file/file.c
file/file.h
file/fsmagic.c
file/print.c
file/readelf.c
file/softmagic.c

index 9c36dac..4bce795 100644 (file)
@@ -76,7 +76,7 @@ const char *default_magicfile = MAGIC;
  * extend the sign bit if the comparison is to be signed
  */
 uint32_t
-signextend(struct magic *m, uint32_t v)
+file_signextend(struct magic *m, uint32_t v)
 {
        if (!(m->flag & UNSIGNED))
                switch(m->type) {
@@ -85,32 +85,32 @@ signextend(struct magic *m, uint32_t v)
                 * vital.  When later compared with the data,
                 * the sign extension must have happened.
                 */
-               case BYTE:
+               case FILE_BYTE:
                        v = (char) v;
                        break;
-               case SHORT:
-               case BESHORT:
-               case LESHORT:
+               case FILE_SHORT:
+               case FILE_BESHORT:
+               case FILE_LESHORT:
                        v = (short) v;
                        break;
-               case DATE:
-               case BEDATE:
-               case LEDATE:
-               case LDATE:
-               case BELDATE:
-               case LELDATE:
-               case LONG:
-               case BELONG:
-               case LELONG:
+               case FILE_DATE:
+               case FILE_BEDATE:
+               case FILE_LEDATE:
+               case FILE_LDATE:
+               case FILE_BELDATE:
+               case FILE_LELDATE:
+               case FILE_LONG:
+               case FILE_BELONG:
+               case FILE_LELONG:
                        v = (int32_t) v;
                        break;
-               case STRING:
-               case PSTRING:
+               case FILE_STRING:
+               case FILE_PSTRING:
                        break;
-               case REGEX:
+               case FILE_REGEX:
                        break;
                default:
-                       magwarn("can't happen: m->type=%d\n", m->type);
+                       file_magwarn("can't happen: m->type=%d\n", m->type);
                        return -1;
                }
        return v;
@@ -284,12 +284,12 @@ getvalue(struct magic *m, /*@out@*/ char **p)
 {
        int slen;
 
-       if (m->type == STRING || m->type == PSTRING || m->type == REGEX) {
+       if (m->type == FILE_STRING || m->type == FILE_PSTRING || m->type == FILE_REGEX) {
                *p = getstr(*p, m->value.s, sizeof(m->value.s), &slen);
                m->vallen = slen;
        } else
                if (m->reln != 'x') {
-                       m->value.l = signextend(m, strtoul(*p, p, 0));
+                       m->value.l = file_signextend(m, strtoul(*p, p, 0));
                        eatsize(p);
                }
        return 0;
@@ -340,11 +340,11 @@ parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
        /* get offset, then skip over it */
        m->offset = (int) strtoul(l,&t,0);
         if (l == t)
-               magwarn("offset %s invalid", l);
+               file_magwarn("offset %s invalid", l);
         l = t;
 
        if (m->flag & INDIR) {
-               m->in_type = LONG;
+               m->in_type = FILE_LONG;
                m->in_offset = 0;
                /*
                 * read [.lbs][+-]nnnnn)
@@ -353,66 +353,66 @@ parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
                        l++;
                        switch (*l) {
                        case 'l':
-                               m->in_type = LELONG;
+                               m->in_type = FILE_LELONG;
                                break;
                        case 'L':
-                               m->in_type = BELONG;
+                               m->in_type = FILE_BELONG;
                                break;
                        case 'h':
                        case 's':
-                               m->in_type = LESHORT;
+                               m->in_type = FILE_LESHORT;
                                break;
                        case 'H':
                        case 'S':
-                               m->in_type = BESHORT;
+                               m->in_type = FILE_BESHORT;
                                break;
                        case 'c':
                        case 'b':
                        case 'C':
                        case 'B':
-                               m->in_type = BYTE;
+                               m->in_type = FILE_BYTE;
                                break;
                        default:
-                               magwarn("indirect offset type %c invalid", *l);
+                               file_magwarn("indirect offset type %c invalid", *l);
                                break;
                        }
                        l++;
                }
                if (*l == '~') {
-                       m->in_op = OPINVERSE;
+                       m->in_op = FILE_OPINVERSE;
                        l++;
                }
                switch (*l) {
                case '&':
-                       m->in_op |= OPAND;
+                       m->in_op |= FILE_OPAND;
                        l++;
                        break;
                case '|':
-                       m->in_op |= OPOR;
+                       m->in_op |= FILE_OPOR;
                        l++;
                        break;
                case '^':
-                       m->in_op |= OPXOR;
+                       m->in_op |= FILE_OPXOR;
                        l++;
                        break;
                case '+':
-                       m->in_op |= OPADD;
+                       m->in_op |= FILE_OPADD;
                        l++;
                        break;
                case '-':
-                       m->in_op |= OPMINUS;
+                       m->in_op |= FILE_OPMINUS;
                        l++;
                        break;
                case '*':
-                       m->in_op |= OPMULTIPLY;
+                       m->in_op |= FILE_OPMULTIPLY;
                        l++;
                        break;
                case '/':
-                       m->in_op |= OPDIVIDE;
+                       m->in_op |= FILE_OPDIVIDE;
                        l++;
                        break;
                case '%':
-                       m->in_op |= OPMODULO;
+                       m->in_op |= FILE_OPMODULO;
                        l++;
                        break;
                }
@@ -421,7 +421,7 @@ parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
                else
                        t = l;
                if (*t++ != ')') 
-                       magwarn("missing ')' in indirect offset");
+                       file_magwarn("missing ')' in indirect offset");
                l = t;
        }
 
@@ -454,115 +454,115 @@ parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
 
        /* get type, skip it */
        if (strncmp(l, "char", NBYTE)==0) {     /* HP/UX compat */
-               m->type = BYTE;
+               m->type = FILE_BYTE;
                l += NBYTE;
        } else if (strncmp(l, "byte", NBYTE)==0) {
-               m->type = BYTE;
+               m->type = FILE_BYTE;
                l += NBYTE;
        } else if (strncmp(l, "short", NSHORT)==0) {
-               m->type = SHORT;
+               m->type = FILE_SHORT;
                l += NSHORT;
        } else if (strncmp(l, "long", NLONG)==0) {
-               m->type = LONG;
+               m->type = FILE_LONG;
                l += NLONG;
        } else if (strncmp(l, "string", NSTRING)==0) {
-               m->type = STRING;
+               m->type = FILE_STRING;
                l += NSTRING;
        } else if (strncmp(l, "date", NDATE)==0) {
-               m->type = DATE;
+               m->type = FILE_DATE;
                l += NDATE;
        } else if (strncmp(l, "beshort", NBESHORT)==0) {
-               m->type = BESHORT;
+               m->type = FILE_BESHORT;
                l += NBESHORT;
        } else if (strncmp(l, "belong", NBELONG)==0) {
-               m->type = BELONG;
+               m->type = FILE_BELONG;
                l += NBELONG;
        } else if (strncmp(l, "bedate", NBEDATE)==0) {
-               m->type = BEDATE;
+               m->type = FILE_BEDATE;
                l += NBEDATE;
        } else if (strncmp(l, "leshort", NLESHORT)==0) {
-               m->type = LESHORT;
+               m->type = FILE_LESHORT;
                l += NLESHORT;
        } else if (strncmp(l, "lelong", NLELONG)==0) {
-               m->type = LELONG;
+               m->type = FILE_LELONG;
                l += NLELONG;
        } else if (strncmp(l, "ledate", NLEDATE)==0) {
-               m->type = LEDATE;
+               m->type = FILE_LEDATE;
                l += NLEDATE;
        } else if (strncmp(l, "pstring", NPSTRING)==0) {
-               m->type = PSTRING;
+               m->type = FILE_PSTRING;
                l += NPSTRING;
        } else if (strncmp(l, "ldate", NLDATE)==0) {
-               m->type = LDATE;
+               m->type = FILE_LDATE;
                l += NLDATE;
        } else if (strncmp(l, "beldate", NBELDATE)==0) {
-               m->type = BELDATE;
+               m->type = FILE_BELDATE;
                l += NBELDATE;
        } else if (strncmp(l, "leldate", NLELDATE)==0) {
-               m->type = LELDATE;
+               m->type = FILE_LELDATE;
                l += NLELDATE;
        } else if (strncmp(l, "regex", NREGEX)==0) {
-               m->type = REGEX;
+               m->type = FILE_REGEX;
                l += sizeof("regex");
        } else {
-               magwarn("type %s invalid", l);
+               file_magwarn("type %s invalid", l);
                return -1;
        }
        /* New-style anding: "0 byte&0x80 =0x80 dynamically linked" */
        /* New and improved: ~ & | ^ + - * / % -- exciting, isn't it? */
        if (*l == '~') {
-               if (STRING != m->type && PSTRING != m->type)
-                       m->mask_op = OPINVERSE;
+               if (m->type != FILE_STRING && m->type != FILE_PSTRING)
+                       m->mask_op = FILE_OPINVERSE;
                ++l;
        }
        switch (*l) {
        case '&':
-               m->mask_op |= OPAND;
+               m->mask_op |= FILE_OPAND;
                ++l;
-               m->mask = signextend(m, strtoul(l, &l, 0));
+               m->mask = file_signextend(m, strtoul(l, &l, 0));
                eatsize(&l);
                break;
        case '|':
-               m->mask_op |= OPOR;
+               m->mask_op |= FILE_OPOR;
                ++l;
-               m->mask = signextend(m, strtoul(l, &l, 0));
+               m->mask = file_signextend(m, strtoul(l, &l, 0));
                eatsize(&l);
                break;
        case '^':
-               m->mask_op |= OPXOR;
+               m->mask_op |= FILE_OPXOR;
                ++l;
-               m->mask = signextend(m, strtoul(l, &l, 0));
+               m->mask = file_signextend(m, strtoul(l, &l, 0));
                eatsize(&l);
                break;
        case '+':
-               m->mask_op |= OPADD;
+               m->mask_op |= FILE_OPADD;
                ++l;
-               m->mask = signextend(m, strtoul(l, &l, 0));
+               m->mask = file_signextend(m, strtoul(l, &l, 0));
                eatsize(&l);
                break;
        case '-':
-               m->mask_op |= OPMINUS;
+               m->mask_op |= FILE_OPMINUS;
                ++l;
-               m->mask = signextend(m, strtoul(l, &l, 0));
+               m->mask = file_signextend(m, strtoul(l, &l, 0));
                eatsize(&l);
                break;
        case '*':
-               m->mask_op |= OPMULTIPLY;
+               m->mask_op |= FILE_OPMULTIPLY;
                ++l;
-               m->mask = signextend(m, strtoul(l, &l, 0));
+               m->mask = file_signextend(m, strtoul(l, &l, 0));
                eatsize(&l);
                break;
        case '%':
-               m->mask_op |= OPMODULO;
+               m->mask_op |= FILE_OPMODULO;
                ++l;
-               m->mask = signextend(m, strtoul(l, &l, 0));
+               m->mask = file_signextend(m, strtoul(l, &l, 0));
                eatsize(&l);
                break;
        case '/':
-               if (STRING != m->type && PSTRING != m->type) {
-                       m->mask_op |= OPDIVIDE;
+               if (m->type != FILE_STRING && m->type != FILE_PSTRING) {
+                       m->mask_op |= FILE_OPDIVIDE;
                        ++l;
-                       m->mask = signextend(m, strtoul(l, &l, 0));
+                       m->mask = file_signextend(m, strtoul(l, &l, 0));
                        eatsize(&l);
                } else {
                        m->mask = 0L;
@@ -579,7 +579,7 @@ parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
                                            STRING_COMPACT_OPTIONAL_BLANK;
                                        /*@switchbreak@*/ break;
                                default:
-                                       magwarn("string extension %c invalid",
+                                       file_magwarn("string extension %c invalid",
                                            *l);
                                        return -1;
                                }
@@ -606,7 +606,7 @@ parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
                }
                break;
        case '!':
-               if (m->type != STRING && m->type != PSTRING) {
+               if (m->type != FILE_STRING && m->type != FILE_PSTRING) {
                        m->reln = *l;
                        ++l;
                        break;
@@ -629,7 +629,7 @@ parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
        /*
         * TODO finish this macro and start using it!
         * #define offsetcheck {if (offset > HOWMANY-1) 
-        *      magwarn("offset too big"); }
+        *      file_magwarn("offset too big"); }
         */
 
        /*
@@ -650,8 +650,8 @@ GetDesc:
                {};
 
 #ifndef COMPILE_ONLY
-       if (action == CHECK) {
-               mdump(m);
+       if (action == FILE_CHECK) {
+               file_mdump(m);
        }
 #endif
        ++(*nmagicp);           /* make room for next */
@@ -663,7 +663,7 @@ GetDesc:
  * Print a string containing C character escapes.
  */
 void
-showstr(FILE *fp, const char *s, int len)
+file_showstr(FILE *fp, const char *s, size_t len)
 {
        char    c;
 
@@ -761,7 +761,7 @@ void bs1(struct magic *m)
        m->cont_level = swap2(m->cont_level);
        m->offset = swap4(m->offset);
        m->in_offset = swap4(m->in_offset);
-       if (m->type != STRING)
+       if (m->type != FILE_STRING)
                m->value.l = swap4(m->value.l);
        m->mask = swap4(m->mask);
 }
@@ -829,7 +829,7 @@ apprentice_file(fmagic fm, /*@out@*/ struct magic **magicp,
        *magicp = (struct magic *) xcalloc(sizeof(**magicp), maxmagic);
 
        /* parse it */
-       if (action == CHECK)    /* print silly verbose header for USG compat. */
+       if (action == FILE_CHECK)       /* print silly verbose header for USG compat. */
                (void) printf("%s\n", hdr);
 
        for (fm->lineno = 1; fgets(line, BUFSIZ, f) != NULL; fm->lineno++) {
@@ -1014,7 +1014,7 @@ apprentice_1(fmagic fm, const char *fn, int action)
        struct mlist *ml;
        int rv = -1;
 
-       if (action == COMPILE) {
+       if (action == FILE_COMPILE) {
                rv = apprentice_file(fm, &magic, &nmagic, fn, action);
                if (rv)
                        return rv;
@@ -1087,7 +1087,7 @@ fmagicSetup(fmagic fm, const char *fn, int action)
        if (errs == -1)
                (void) fprintf(stderr, "%s: couldn't find any magic files!\n",
                    __progname);
-       if (action == CHECK && errs)
+       if (action == FILE_CHECK && errs)
                exit(EXIT_FAILURE);
 
        free(mfn);
index 37ef00b..226b2dd 100644 (file)
@@ -542,11 +542,11 @@ fmagicA(fmagic fm)
         */
        switch (is_tar(fm)) {
        case 1:
-               fmagicPrintf(fm, ((fm->flags & FMAGIC_FLAGS_MIME)
+               file_printf(fm, ((fm->flags & FMAGIC_FLAGS_MIME)
                        ? "application/x-tar" : "tar archive"));
                return 1;
        case 2:
-               fmagicPrintf(fm, ((fm->flags & FMAGIC_FLAGS_MIME)
+               file_printf(fm, ((fm->flags & FMAGIC_FLAGS_MIME)
                        ? "application/x-tar, POSIX" : "POSIX tar archive"));
                return 1;
        }
@@ -708,26 +708,26 @@ subtype_identified:
 
        if ((fm->flags & FMAGIC_FLAGS_MIME)) {
                if (subtype_mime != NULL)
-                       fmagicPrintf(fm, subtype_mime);
+                       file_printf(fm, subtype_mime);
                else
-                       fmagicPrintf(fm, "text/plain");
+                       file_printf(fm, "text/plain");
 
                if (code_mime != NULL) {
-                       fmagicPrintf(fm, "; charset=");
-                       fmagicPrintf(fm, code_mime);
+                       file_printf(fm, "; charset=");
+                       file_printf(fm, code_mime);
                }
        } else {
-               fmagicPrintf(fm, code);
+               file_printf(fm, code);
 
                if (subtype != NULL) {
-                       fmagicPrintf(fm, " ");
-                       fmagicPrintf(fm, subtype);
+                       file_printf(fm, " ");
+                       file_printf(fm, subtype);
                }
-               fmagicPrintf(fm, " ");
-               fmagicPrintf(fm, type);
+               file_printf(fm, " ");
+               file_printf(fm, type);
 
                if (has_long_lines)
-                       fmagicPrintf(fm, ", with very long lines");
+                       file_printf(fm, ", with very long lines");
 
                /*
                 * Only report line terminators if we find one other than LF,
@@ -735,37 +735,37 @@ subtype_identified:
                 */
                if ((n_crlf == 0 && n_cr == 0 && n_nel == 0 && n_lf == 0) ||
                    (n_crlf != 0 || n_cr != 0 || n_nel != 0)) {
-                       fmagicPrintf(fm, ", with");
+                       file_printf(fm, ", with");
 
                        if (n_crlf == 0 && n_cr == 0 && n_nel == 0 && n_lf == 0)
-                               fmagicPrintf(fm, " no");
+                               file_printf(fm, " no");
                        else {
                                if (n_crlf) {
-                                       fmagicPrintf(fm, " CRLF");
+                                       file_printf(fm, " CRLF");
                                        if (n_cr || n_lf || n_nel)
-                                               fmagicPrintf(fm, ",");
+                                               file_printf(fm, ",");
                                }
                                if (n_cr) {
-                                       fmagicPrintf(fm, " CR");
+                                       file_printf(fm, " CR");
                                        if (n_lf || n_nel)
-                                               fmagicPrintf(fm, ",");
+                                               file_printf(fm, ",");
                                }
                                if (n_lf) {
-                                       fmagicPrintf(fm, " LF");
+                                       file_printf(fm, " LF");
                                        if (n_nel)
-                                               fmagicPrintf(fm, ",");
+                                               file_printf(fm, ",");
                                }
                                if (n_nel)
-                                       fmagicPrintf(fm, " NEL");
+                                       file_printf(fm, " NEL");
                        }
 
-                       fmagicPrintf(fm, " line terminators");
+                       file_printf(fm, " line terminators");
                }
 
                if (has_escapes)
-                       fmagicPrintf(fm, ", with escape sequences");
+                       file_printf(fm, ", with escape sequences");
                if (has_backspace)
-                       fmagicPrintf(fm, ", with overstriking");
+                       file_printf(fm, ", with overstriking");
        }
 
        return 1;
index 6fd8de3..b8ede4c 100644 (file)
@@ -87,7 +87,7 @@ sread(int fd, /*@out@*/ void *buf, size_t n)
 }
 
 int
-pipe2file(int fd, void *startbuf, size_t nbytes)
+file_pipe2file(int fd, const void *startbuf, size_t nbytes)
 {
        char buf[4096];
        int r, tfd;
index ee69d21..a146e36 100644 (file)
@@ -246,10 +246,10 @@ main(int argc, char **argv)
                        fm->flags |= FMAGIC_FLAGS_BRIEF;
                        /*@switchbreak@*/ break;
                case 'c':
-                       action = CHECK;
+                       action = FILE_CHECK;
                        /*@switchbreak@*/ break;
                case 'C':
-                       action = COMPILE;
+                       action = FILE_COMPILE;
                        /*@switchbreak@*/ break;
                case 'd':
                        fm->flags |= FMAGIC_FLAGS_DEBUG;
index 72b9e8c..a5a7e9f 100644 (file)
@@ -1,29 +1,38 @@
+ /*
+ * Copyright (c) Ian F. Darwin 1986-1995.
+ * Software written by Ian F. Darwin and others;
+ * maintained 1995-present by Christos Zoulas and others.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice immediately at the beginning of the file, without modification,
+ *    this list of conditions, and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Ian F. Darwin and others.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *  
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 /*
  * file.h - definitions for file(1) program
- * @(#)Id: file.h,v 1.43 2002/07/03 18:57:52 christos Exp 
- *
- * Copyright (c) Ian F. Darwin, 1987.
- * Written by Ian F. Darwin.
- *
- * This software is not subject to any license of the American Telephone
- * and Telegraph Company or of the Regents of the University of California.
- *
- * Permission is granted to anyone to use this software for any purpose on
- * any computer system, and to alter it and redistribute it freely, subject
- * to the following restrictions:
- *
- * 1. The author is not responsible for the consequences of use of this
- *    software, no matter how awful, even if they arise from flaws in it.
- *
- * 2. The origin of this software must not be misrepresented, either by
- *    explicit claim or by omission.  Since few users ever read sources,
- *    credits must appear in the documentation.
- *
- * 3. Altered versions must be plainly marked as such, and must not be
- *    misrepresented as being the original software.  Since few users
- *    ever read sources, credits must appear in the documentation.
- *
- * 4. This notice may not be removed or altered.
+ * @(#) Id: file.h,v 1.53 2003/03/28 21:02:03 christos Exp 
  */
 
 #ifndef __file_h__
 # define HOWMANY 65536         /* how much of the file to look at */
 #endif
 #define MAXMAGIS 4096          /* max entries in /etc/magic */
-#define MAXDESC        50              /* max leng of text description */
+#define MAXDESC        64              /* max leng of text description */
 #define MAXstring 32           /* max leng of "string" types */
 
 #define MAGICNO                0xF11E041C
-#define VERSIONNO      1
+#define VERSIONNO      2
+#define FILE_MAGICSIZE (32 * 4)
 
-#define CHECK  1
-#define COMPILE        2
+#define FILE_CHECK     1
+#define FILE_COMPILE   2
 
 struct magic {
+       /* Word 1 */
        uint16_t cont_level;    /* level of ">" */
        uint8_t nospflag;       /* supress space character */
        uint8_t flag;
 #define INDIR  1               /* if '>(...)' appears,  */
 #define        UNSIGNED 2              /* comparison is unsigned */
 #define OFFADD 4               /* if '>&' appears,  */
+       /* Word 2 */
        uint8_t reln;           /* relation (0=eq, '>'=gt, etc) */
        uint8_t vallen;         /* length of string value, if any */
        uint8_t type;           /* int, short, long or string. */
        uint8_t in_type;        /* type of indirrection */
-#define                        BYTE    1
-#define                                SHORT   2
-#define                                LONG    4
-#define                                STRING  5
-#define                                DATE    6
-#define                                BESHORT 7
-#define                                BELONG  8
-#define                                BEDATE  9
-#define                                LESHORT 10
-#define                                LELONG  11
-#define                                LEDATE  12
-#define                                PSTRING 13
-#define                                LDATE   14
-#define                                BELDATE 15
-#define                                LELDATE 16
-#define                                REGEX   17
+#define                        FILE_BYTE       1
+#define                                FILE_SHORT      2
+#define                                FILE_LONG       4
+#define                                FILE_STRING     5
+#define                                FILE_DATE       6
+#define                                FILE_BESHORT    7
+#define                                FILE_BELONG     8
+#define                                FILE_BEDATE     9
+#define                                FILE_LESHORT    10
+#define                                FILE_LELONG     11
+#define                                FILE_LEDATE     12
+#define                                FILE_PSTRING    13
+#define                                FILE_LDATE      14
+#define                                FILE_BELDATE    15
+#define                                FILE_LELDATE    16
+#define                                FILE_REGEX      17
+       /* Word 3 */
        uint8_t in_op;          /* operator for indirection */
        uint8_t mask_op;        /* operator for mask */
-#define                                OPAND   1
-#define                                OPOR    2
-#define                                OPXOR   3
-#define                                OPADD   4
-#define                                OPMINUS 5
-#define                                OPMULTIPLY      6
-#define                                OPDIVIDE        7
-#define                                OPMODULO        8
-#define                                OPINVERSE       0x80
+       uint8_t dummy1;
+       uint8_t dummy2;
+#define                                FILE_OPS        "&|^+-*%/"
+#define                                FILE_OPAND      0
+#define                                FILE_OPOR       1
+#define                                FILE_OPXOR      2
+#define                                FILE_OPADD      3
+#define                                FILE_OPMINUS    4
+#define                                FILE_OPMULTIPLY 5
+#define                                FILE_OPDIVIDE   6
+#define                                FILE_OPMODULO   7
+#define                                FILE_OPINVERSE  0x80
+       /* Word 4 */
        int32_t offset;         /* offset to magic number */
+       /* Word 5 */
        int32_t in_offset;      /* offset from indirection */
+       /* Word 6 */
+       uint32_t mask;  /* mask before comparison with value */
+       /* Word 7 */
+       uint32_t dummy3;
+       /* Word 8 */
+       uint32_t dummp4;
+       /* Words 9-16 */
        union VALUETYPE {
                uint8_t b;
                uint16_t h;
@@ -93,9 +118,9 @@ struct magic {
                uint8_t hs[2];  /* 2 bytes of a fixed-endian "short" */
                uint8_t hl[4];  /* 4 bytes of a fixed-endian "long" */
        } value;                /* either number or string */
-       uint32_t mask;  /* mask before comparison with value */
+       /* Words 17..31 */
        char desc[MAXDESC];     /* description */
-} __attribute__((__packed__));
+};
 
 #define BIT(A)   (1 << (A))
 #define STRING_IGNORE_LOWERCASE                BIT(0)
@@ -110,6 +135,9 @@ struct magic {
 struct mlist {
        struct magic *magic;            /* array of magic entries */
        uint32_t nmagic;                /* number of entries in array */
+       int mapped;  /* allocation type: 0 => apprentice_file
+                     *                  1 => apprentice_map + malloc
+                     *                  2 => apprentice_map + mmap */
 /*@relnull@*/
        struct mlist *next;
 /*@relnull@*/
@@ -192,27 +220,27 @@ extern int fmagicZ(fmagic fm)
        /*@globals fileSystem, internalState @*/
        /*@modifies fm, fileSystem, internalState @*/;
 
-extern void fmagicPrintf(const fmagic fm, const char *f, ...)
+extern void file_printf(const fmagic fm, const char *f, ...)
        /*@modifies fm @*/;
 
 /*@observer@*/
-extern char *fmttime(long v, int local)
+extern const char *file_fmttime(uint32_t v, int local)
        /*@*/;
 
-extern void magwarn(const char *f, ...)
+extern void file_magwarn(const char *f, ...)
        /*@globals fileSystem @*/
        /*@modifies fileSystem @*/;
-extern void mdump(struct magic *m)
+extern void file_mdump(struct magic *m)
        /*@globals fileSystem @*/
        /*@modifies fileSystem @*/;
-extern void showstr(FILE *fp, const char *s, int len)
+extern void file_showstr(FILE *fp, const char *s, size_t len)
        /*@globals fileSystem @*/
        /*@modifies fp, fileSystem @*/;
 
-extern uint32_t signextend(struct magic *m, uint32_t v)
+extern uint32_t file_signextend(struct magic *m, uint32_t v)
        /*@globals fileSystem @*/
        /*@modifies fileSystem @*/;
-extern int pipe2file(int fd, void *startbuf, size_t nbytes)
+extern int file_pipe2file(int fd, const void *startbuf, size_t nbytes)
        /*@globals errno, fileSystem, internalState @*/
        /*@modifies errno, fileSystem, internalState @*/;
 
index 81e7a0e..ec225f1 100644 (file)
@@ -56,31 +56,31 @@ fmagicD(fmagic fm)
        if (ret) {
                /* Yes, I do mean stdout. */
                /* No \n, caller will provide. */
-               fmagicPrintf(fm, "can't stat `%s' (%s).", fn, strerror(errno));
+               file_printf(fm, "can't stat `%s' (%s).", fn, strerror(errno));
                return 1;
        }
 
        if ((fm->flags & FMAGIC_FLAGS_MIME)) {
                if ((st->st_mode & S_IFMT) != S_IFREG) {
-                       fmagicPrintf(fm, "application/x-not-regular-file");
+                       file_printf(fm, "application/x-not-regular-file");
                        return 1;
                }
        }
        else {
 #if defined(S_ISUID) || defined(__LCLINT__)
-               if (st->st_mode & S_ISUID) fmagicPrintf(fm, "setuid ");
+               if (st->st_mode & S_ISUID) file_printf(fm, "setuid ");
 #endif
 #if defined(S_ISGID) || defined(__LCLINT__)
-               if (st->st_mode & S_ISGID) fmagicPrintf(fm, "setgid ");
+               if (st->st_mode & S_ISGID) file_printf(fm, "setgid ");
 #endif
 #if defined(S_ISVTX) || defined(__LCLINT__)
-               if (st->st_mode & S_ISVTX) fmagicPrintf(fm, "sticky ");
+               if (st->st_mode & S_ISVTX) file_printf(fm, "sticky ");
 #endif
        }
        
        switch (st->st_mode & S_IFMT) {
        case S_IFDIR:
-               fmagicPrintf(fm, "directory");
+               file_printf(fm, "directory");
                return 1;
 #if defined(S_IFCHR) || defined(__LCLINT__)
        case S_IFCHR:
@@ -93,18 +93,18 @@ fmagicD(fmagic fm)
                        break;
 #ifdef HAVE_STRUCT_STAT_ST_RDEV
 # ifdef dv_unit
-               fmagicPrintf(fm, "character special (%d/%d/%d)",
+               file_printf(fm, "character special (%d/%d/%d)",
                        major(st->st_rdev),
                        dv_unit(st->st_rdev),
                        dv_subunit(st->st_rdev));
 # else
 /*@-shiftimplementation@*/
-               fmagicPrintf(fm, "character special (%ld/%ld)",
+               file_printf(fm, "character special (%ld/%ld)",
                        (long) major(st->st_rdev), (long) minor(st->st_rdev));
 /*@=shiftimplementation@*/
 # endif
 #else
-               fmagicPrintf(fm, "character special");
+               file_printf(fm, "character special");
 #endif
                return 1;
 #endif
@@ -119,30 +119,30 @@ fmagicD(fmagic fm)
                        break;
 #ifdef HAVE_STRUCT_STAT_ST_RDEV
 # ifdef dv_unit
-               fmagicPrintf(fm, "block special (%d/%d/%d)",
+               file_printf(fm, "block special (%d/%d/%d)",
                        major(st->st_rdev),
                        dv_unit(st->st_rdev),
                        dv_subunit(st->st_rdev));
 # else
 /*@-shiftimplementation@*/
-               fmagicPrintf(fm, "block special (%ld/%ld)",
+               file_printf(fm, "block special (%ld/%ld)",
                        (long) major(st->st_rdev), (long) minor(st->st_rdev));
 /*@=shiftimplementation@*/
 # endif
 #else
-               fmagicPrintf(fm, "block special");
+               file_printf(fm, "block special");
 #endif
                return 1;
 #endif
        /* TODO add code to handle V7 MUX and Blit MUX files */
 #if defined(S_IFIFO) || defined(__LCLINT__)
        case S_IFIFO:
-               fmagicPrintf(fm, "fifo (named pipe)");
+               file_printf(fm, "fifo (named pipe)");
                return 1;
 #endif
 #if defined(S_IFDOOR)
        case S_IFDOOR:
-               fmagicPrintf(fm, "door");
+               file_printf(fm, "door");
                return 1;
 #endif
 #if defined(S_IFLNK) || defined(__LCLINT__)
@@ -154,7 +154,7 @@ fmagicD(fmagic fm)
 
                        buf[0] = '\0';
                        if ((nch = readlink(fn, buf, BUFSIZ-1)) <= 0) {
-                               fmagicPrintf(fm, "unreadable symlink (%s).", strerror(errno));
+                               file_printf(fm, "unreadable symlink (%s).", strerror(errno));
                                return 1;
                        }
                        buf[nch] = '\0';        /* readlink(2) needs this */
@@ -163,7 +163,7 @@ fmagicD(fmagic fm)
 /*@-branchstate@*/
                        if (*buf == '/') {
                            if (stat(buf, &tstatbuf) < 0) {
-                               fmagicPrintf(fm, "broken symbolic link to %s", buf);
+                               file_printf(fm, "broken symbolic link to %s", buf);
                                return 1;
                            }
                        }
@@ -181,7 +181,7 @@ fmagicD(fmagic fm)
                                tmp = buf2;
                            }
                            if (stat(tmp, &tstatbuf) < 0) {
-                               fmagicPrintf(fm, "broken symbolic link to %s", buf);
+                               file_printf(fm, "broken symbolic link to %s", buf);
                                return 1;
                            }
                         }
@@ -189,11 +189,11 @@ fmagicD(fmagic fm)
 
                        /* Otherwise, handle it. */
                        if ((fm->flags & FMAGIC_FLAGS_FOLLOW)) {
-                               fmagicPrintf(fm, "\n");
+                               file_printf(fm, "\n");
                                xx = fmagicProcess(fm, buf, strlen(buf));
                                return 1;
                        } else { /* just print what it points to */
-                               fmagicPrintf(fm, "symbolic link to %s", buf);
+                               file_printf(fm, "symbolic link to %s", buf);
                        }
                }
                return 1;
@@ -201,7 +201,7 @@ fmagicD(fmagic fm)
 #if defined(S_IFSOCK)
 #ifndef __COHERENT__
        case S_IFSOCK:
-               fmagicPrintf(fm, "socket");
+               file_printf(fm, "socket");
                return 1;
 #endif
 #endif
@@ -225,7 +225,7 @@ fmagicD(fmagic fm)
         * when we read the file.)
         */
        if (!(fm->flags & FMAGIC_FLAGS_SPECIAL) && st->st_size == 0) {
-               fmagicPrintf(fm, ((fm->flags & FMAGIC_FLAGS_MIME)
+               file_printf(fm, ((fm->flags & FMAGIC_FLAGS_MIME)
                        ? "application/x-empty" : "empty"));
                return 1;
        }
@@ -262,7 +262,7 @@ fmagicF(fmagic fm, int zfl)
                return 'a';
 
        /* abandon hope, all ye who remain here */
-       fmagicPrintf(fm, ((fm->flags & FMAGIC_FLAGS_MIME)
+       file_printf(fm, ((fm->flags & FMAGIC_FLAGS_MIME)
                ? "application/octet-stream" : "data"));
        return '\0';
 }
@@ -297,7 +297,7 @@ fmagicProcess(fmagic fm, const char *fn, int wid)
 /*@=branchstate@*/
 
        if (wid > 0 && !(fm->flags & FMAGIC_FLAGS_BRIEF))
-            fmagicPrintf(fm, "%s:%*s ", fm->fn, 
+            file_printf(fm, "%s:%*s ", fm->fn, 
                           (int) (wid - strlen(fm->fn)), "");
 
        if (fm->fn != stdname) {
@@ -310,10 +310,10 @@ fmagicProcess(fmagic fm, const char *fn, int wid)
                if ((fm->fd = open(fm->fn, O_RDONLY)) < 0) {
                        /* We can't open it, but we were able to stat it. */
                        if (fm->sb.st_mode & 0002)
-                               fmagicPrintf(fm, "writeable, ");
+                               file_printf(fm, "writeable, ");
                        if (fm->sb.st_mode & 0111)
-                               fmagicPrintf(fm, "executable, ");
-                       fmagicPrintf(fm, "can't read `%s' (%s).", fm->fn, strerror(errno));
+                               file_printf(fm, "executable, ");
+                       file_printf(fm, "can't read `%s' (%s).", fm->fn, strerror(errno));
                        goto exit;
                }
        }
@@ -328,7 +328,7 @@ fmagicProcess(fmagic fm, const char *fn, int wid)
        }
 
        if (fm->nb == 0)
-               fmagicPrintf(fm, ((fm->flags & FMAGIC_FLAGS_MIME)
+               file_printf(fm, ((fm->flags & FMAGIC_FLAGS_MIME)
                        ? "application/x-empty" : "empty"), fm);
        else {
                fm->buf[fm->nb++] = '\0';       /* null-terminate data buffer */
index 6a18b8b..0bc0054 100644 (file)
@@ -44,7 +44,7 @@ fmagic global_fmagic = &myfmagic;
 
 #ifndef COMPILE_ONLY
 void
-mdump(struct magic *m)
+file_mdump(struct magic *m)
 {
        /*@observer@*/
        static const char *typ[] = { "invalid", "byte", "short", "invalid",
@@ -65,7 +65,7 @@ mdump(struct magic *m)
                               /* Note: type is unsigned */
                               (m->in_type < SZOF(typ)) ? 
                                        typ[m->in_type] : "*bad*");
-               if (m->in_op & OPINVERSE)
+               if (m->in_op & FILE_OPINVERSE)
                        (void) fputc('~', stderr);
                (void) fprintf(stderr, "%c%d),",
                               ((m->in_op&0x7F) < SZOF(optyp)) ? 
@@ -75,13 +75,13 @@ mdump(struct magic *m)
        (void) fprintf(stderr, " %s%s", (m->flag & UNSIGNED) ? "u" : "",
                       /* Note: type is unsigned */
                       (m->type < SZOF(typ)) ? typ[m->type] : "*bad*");
-       if (m->mask_op & OPINVERSE)
+       if (m->mask_op & FILE_OPINVERSE)
                (void) fputc('~', stderr);
        if (m->mask) {
                ((m->mask_op&0x7F) < SZOF(optyp)) ? 
                        (void) fputc(optyp[m->mask_op&0x7F], stderr) :
                        (void) fputc('?', stderr);
-               if(STRING != m->type || PSTRING != m->type)
+               if (m->type != FILE_STRING || m->type != FILE_PSTRING)
                        (void) fprintf(stderr, "%.8x", m->mask);
                else {
                        if (m->mask & STRING_IGNORE_LOWERCASE) 
@@ -98,29 +98,31 @@ mdump(struct magic *m)
 
        if (m->reln != 'x') {
                switch (m->type) {
-               case BYTE:
-               case SHORT:
-               case LONG:
-               case LESHORT:
-               case LELONG:
-               case BESHORT:
-               case BELONG:
+               case FILE_BYTE:
+               case FILE_SHORT:
+               case FILE_LONG:
+               case FILE_LESHORT:
+               case FILE_LELONG:
+               case FILE_BESHORT:
+               case FILE_BELONG:
                        (void) fprintf(stderr, "%d", m->value.l);
                        break;
-               case STRING:
-               case PSTRING:
-               case REGEX:
-                       showstr(stderr, m->value.s, -1);
+               case FILE_STRING:
+               case FILE_PSTRING:
+               case FILE_REGEX:
+                       file_showstr(stderr, m->value.s, ~0U);
                        break;
-               case DATE:
-               case LEDATE:
-               case BEDATE:
-                       (void)fprintf(stderr, "%s,", fmttime(m->value.l, 1));
+               case FILE_DATE:
+               case FILE_LEDATE:
+               case FILE_BEDATE:
+                       (void)fprintf(stderr, "%s,",
+                           file_fmttime(m->value.l, 1));
                        break;
-               case LDATE:
-               case LELDATE:
-               case BELDATE:
-                       (void)fprintf(stderr, "%s,", fmttime(m->value.l, 0));
+               case FILE_LDATE:
+               case FILE_LELDATE:
+               case FILE_BELDATE:
+                       (void)fprintf(stderr, "%s,",
+                           file_fmttime(m->value.l, 0));
                        break;
                default:
                        (void) fputs("*bad*", stderr);
@@ -158,7 +160,7 @@ error(int status, /*@unused@*/ int errnum, const char * format, ...)
 
 /*VARARGS*/
 void
-magwarn(const char *f, ...)
+file_magwarn(const char *f, ...)
 {
        fmagic fm = global_fmagic;
        va_list va;
@@ -179,7 +181,7 @@ magwarn(const char *f, ...)
 }
 
 void
-fmagicPrintf(const fmagic fm, const char *f, ...)
+file_printf(const fmagic fm, const char *f, ...)
 {
        va_list va;
        size_t nob;
@@ -199,8 +201,8 @@ fmagicPrintf(const fmagic fm, const char *f, ...)
 
 
 #ifndef COMPILE_ONLY
-char *
-fmttime(long v, int local)
+const char *
+file_fmttime(uint32_t v, int local)
 {
        char *pp = "???";
        char *rt;
index ca2138e..6e22073 100644 (file)
@@ -144,11 +144,11 @@ doshn(fmagic fm, off_t off, int num, size_t size)
                        /*@notreached@*/
                }
                if (shs_type == SHT_SYMTAB /* || shs_type == SHT_DYNSYM */) {
-                       fmagicPrintf(fm, ", not stripped");
+                       file_printf(fm, ", not stripped");
                        return;
                }
        }
-       fmagicPrintf(fm, ", stripped");
+       file_printf(fm, ", stripped");
 }
 /*@=bounds@*/
 
@@ -249,22 +249,22 @@ dophn_exec(fmagic fm, off_t off, int num, size_t size)
                                        uint32_t *desc =
                                            (uint32_t *)&nbuf[offset];
 
-                                       fmagicPrintf(fm, ", for GNU/");
+                                       file_printf(fm, ", for GNU/");
                                        switch (getu32(fm, desc[0])) {
                                        case GNU_OS_LINUX:
-                                               fmagicPrintf(fm, "Linux");
+                                               file_printf(fm, "Linux");
                                                /*@switchbreak@*/ break;
                                        case GNU_OS_HURD:
-                                               fmagicPrintf(fm, "Hurd");
+                                               file_printf(fm, "Hurd");
                                                /*@switchbreak@*/ break;
                                        case GNU_OS_SOLARIS:
-                                               fmagicPrintf(fm, "Solaris");
+                                               file_printf(fm, "Solaris");
                                                /*@switchbreak@*/ break;
                                        default:
-                                               fmagicPrintf(fm, "<unknown>");
+                                               file_printf(fm, "<unknown>");
                                                /*@switchbreak@*/ break;
                                        }
-                                       fmagicPrintf(fm, " %d.%d.%d",
+                                       file_printf(fm, " %d.%d.%d",
                                            getu32(fm, desc[1]),
                                            getu32(fm, desc[2]),
                                            getu32(fm, desc[3]));
@@ -274,7 +274,7 @@ dophn_exec(fmagic fm, off_t off, int num, size_t size)
                                    strcmp(&nbuf[nameoffset], "NetBSD") == 0 &&
                                    nh_type == NT_NETBSD_VERSION &&
                                    nh_descsz == 4) {
-                                       fmagicPrintf(fm, ", for NetBSD");
+                                       file_printf(fm, ", for NetBSD");
                                        /*
                                         * Version number is stuck at 199905,
                                         * and hence is basically content-free.
@@ -287,7 +287,7 @@ dophn_exec(fmagic fm, off_t off, int num, size_t size)
                                    nh_descsz == 4) {
                                        uint32_t desc = getu32(fm,
                                            *(uint32_t *)&nbuf[offset]);
-                                       fmagicPrintf(fm, ", for FreeBSD");
+                                       file_printf(fm, ", for FreeBSD");
                                        /*
                                         * Contents is __FreeBSD_version,
                                         * whose relation to OS versions is
@@ -298,10 +298,10 @@ dophn_exec(fmagic fm, off_t off, int num, size_t size)
                                         * FreeBSD that use this note.
                                         */
 
-                                       fmagicPrintf(fm, " %d.%d", desc / 100000,
+                                       file_printf(fm, " %d.%d", desc / 100000,
                                            desc / 10000 % 10);
                                        if (desc / 1000 % 10 > 0)
-                                               fmagicPrintf(fm, ".%d",
+                                               file_printf(fm, ".%d",
                                                    desc / 1000 % 10);
                                }
 
@@ -309,7 +309,7 @@ dophn_exec(fmagic fm, off_t off, int num, size_t size)
                                    strcmp(&nbuf[nameoffset], "OpenBSD") == 0 &&
                                    nh_type == NT_OPENBSD_VERSION &&
                                    nh_descsz == 4) {
-                                       fmagicPrintf(fm, ", for OpenBSD");
+                                       file_printf(fm, ", for OpenBSD");
                                        /* Content of note is always 0 */
                                }
                        }
@@ -320,7 +320,7 @@ dophn_exec(fmagic fm, off_t off, int num, size_t size)
                        /*@switchbreak@*/ break;
                }
        }
-       fmagicPrintf(fm, ", %s linked%s", linking_style, shared_libraries);
+       file_printf(fm, ", %s linked%s", linking_style, shared_libraries);
 }
 /*@=bounds@*/
 
@@ -485,7 +485,7 @@ dophn_core(fmagic fm, off_t off, int num, size_t size)
                                        os_style = OS_STYLE_NETBSD;
                                } else
                                        /*@innercontinue@*/ continue;
-                               fmagicPrintf(fm, ", %s-style", os_style_names[os_style]);
+                               file_printf(fm, ", %s-style", os_style_names[os_style]);
                        }
 
                        if (os_style == OS_STYLE_NETBSD &&
@@ -497,7 +497,7 @@ dophn_core(fmagic fm, off_t off, int num, size_t size)
                                 * offset 0x7c, and is up to 32-bytes,
                                 * including the terminating NUL.
                                 */
-                               fmagicPrintf(fm, ", from '%.31s'", &nbuf[offset + 0x7c]);
+                               file_printf(fm, ", from '%.31s'", &nbuf[offset + 0x7c]);
                                
                                /*
                                 * Extract the signal number.  It is at
@@ -505,7 +505,7 @@ dophn_core(fmagic fm, off_t off, int num, size_t size)
                                 */
                                memcpy(&signo, &nbuf[offset + 0x08],
                                    sizeof(signo));
-                               fmagicPrintf(fm, " (signal %u)", getu32(fm, signo));
+                               file_printf(fm, " (signal %u)", getu32(fm, signo));
                        } else
                        if (os_style != OS_STYLE_NETBSD &&
                            nh_type == NT_PRPSINFO) {
@@ -570,7 +570,7 @@ dophn_core(fmagic fm, off_t off, int num, size_t size)
                                        /*
                                         * Well, that worked.
                                         */
-                                       fmagicPrintf(fm, ", from '%.16s'",
+                                       file_printf(fm, ", from '%.16s'",
                                            &nbuf[offset + prpsoffsets(i)]);
                                        /*@innerbreak@*/ break;
 
@@ -602,7 +602,7 @@ fmagicE(fmagic fm)
         * If we can't seek, it must be a pipe, socket or fifo.
         */
        if((lseek(fm->fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
-               fm->fd = pipe2file(fm->fd, fm->buf, fm->nb);
+               fm->fd = file_pipe2file(fm->fd, fm->buf, fm->nb);
 
        /*
         * ELF executables have multiple section headers in arbitrary
index 9a42076..63041b6 100644 (file)
@@ -44,38 +44,38 @@ fmagicSPrint(const fmagic fm, struct magic *m)
     int32_t t = 0;
 
     switch (m->type) {
-    case BYTE:
-       v = signextend(m, p->b);
-       fmagicPrintf(fm, m->desc, (unsigned char) v);
+    case FILE_BYTE:
+       v = file_signextend(m, p->b);
+       file_printf(fm, m->desc, (unsigned char) v);
 /*@-sizeoftype@*/
        t = m->offset + sizeof(char);
 /*@=sizeoftype@*/
        break;
 
-    case SHORT:
-    case BESHORT:
-    case LESHORT:
-       v = signextend(m, p->h);
-       fmagicPrintf(fm, m->desc, (unsigned short) v);
+    case FILE_SHORT:
+    case FILE_BESHORT:
+    case FILE_LESHORT:
+       v = file_signextend(m, p->h);
+       file_printf(fm, m->desc, (unsigned short) v);
 /*@-sizeoftype@*/
        t = m->offset + sizeof(short);
 /*@=sizeoftype@*/
        break;
 
-    case LONG:
-    case BELONG:
-    case LELONG:
-       v = signextend(m, p->l);
-       fmagicPrintf(fm, m->desc, (uint32_t) v);
+    case FILE_LONG:
+    case FILE_BELONG:
+    case FILE_LELONG:
+       v = file_signextend(m, p->l);
+       file_printf(fm, m->desc, (uint32_t) v);
 /*@-sizeoftype@*/
        t = m->offset + sizeof(int32_t);
 /*@=sizeoftype@*/
        break;
 
-    case STRING:
-    case PSTRING:
+    case FILE_STRING:
+    case FILE_PSTRING:
        if (m->reln == '=') {
-           fmagicPrintf(fm, m->desc, m->value.s);
+           file_printf(fm, m->desc, m->value.s);
            t = m->offset + strlen(m->value.s);
        } else {
            if (*m->value.s == '\0') {
@@ -83,31 +83,31 @@ fmagicSPrint(const fmagic fm, struct magic *m)
                if (cp != NULL)
                    *cp = '\0';
            }
-           fmagicPrintf(fm, m->desc, p->s);
+           file_printf(fm, m->desc, p->s);
            t = m->offset + strlen(p->s);
        }
        break;
 
-    case DATE:
-    case BEDATE:
-    case LEDATE:
-       fmagicPrintf(fm, m->desc, fmttime(p->l, 1));
+    case FILE_DATE:
+    case FILE_BEDATE:
+    case FILE_LEDATE:
+       file_printf(fm, m->desc, file_fmttime(p->l, 1));
 /*@-sizeoftype@*/
        t = m->offset + sizeof(time_t);
 /*@=sizeoftype@*/
        break;
 
-    case LDATE:
-    case BELDATE:
-    case LELDATE:
-       fmagicPrintf(fm, m->desc, fmttime(p->l, 0));
+    case FILE_LDATE:
+    case FILE_BELDATE:
+    case FILE_LELDATE:
+       file_printf(fm, m->desc, file_fmttime(p->l, 0));
 /*@-sizeoftype@*/
        t = m->offset + sizeof(time_t);
 /*@=sizeoftype@*/
        break;
 
-    case REGEX:
-       fmagicPrintf(fm, m->desc, p->s);
+    case FILE_REGEX:
+       file_printf(fm, m->desc, p->s);
        t = m->offset + strlen(p->s);
        break;
 
@@ -133,102 +133,102 @@ fmagicSConvert(fmagic fm, struct magic *m)
     union VALUETYPE * p = &fm->val;
 
     switch (m->type) {
-    case BYTE:
+    case FILE_BYTE:
        if (m->mask)
            switch (m->mask_op&0x7F) {
-           case OPAND:
+           case FILE_OPAND:
                p->b &= m->mask;
                /*@innerbreak@*/ break;
-           case OPOR:
+           case FILE_OPOR:
                p->b |= m->mask;
                /*@innerbreak@*/ break;
-           case OPXOR:
+           case FILE_OPXOR:
                p->b ^= m->mask;
                /*@innerbreak@*/ break;
-           case OPADD:
+           case FILE_OPADD:
                p->b += m->mask;
                /*@innerbreak@*/ break;
-           case OPMINUS:
+           case FILE_OPMINUS:
                p->b -= m->mask;
                /*@innerbreak@*/ break;
-           case OPMULTIPLY:
+           case FILE_OPMULTIPLY:
                p->b *= m->mask;
                /*@innerbreak@*/ break;
-           case OPDIVIDE:
+           case FILE_OPDIVIDE:
                p->b /= m->mask;
                /*@innerbreak@*/ break;
-           case OPMODULO:
+           case FILE_OPMODULO:
                p->b %= m->mask;
                /*@innerbreak@*/ break;
            }
-       if (m->mask_op & OPINVERSE)
+       if (m->mask_op & FILE_OPINVERSE)
            p->b = ~p->b;
        return 1;
-    case SHORT:
+    case FILE_SHORT:
        if (m->mask)
            switch (m->mask_op&0x7F) {
-           case OPAND:
+           case FILE_OPAND:
                p->h &= m->mask;
                /*@innerbreak@*/ break;
-           case OPOR:
+           case FILE_OPOR:
                p->h |= m->mask;
                /*@innerbreak@*/ break;
-           case OPXOR:
+           case FILE_OPXOR:
                p->h ^= m->mask;
                /*@innerbreak@*/ break;
-           case OPADD:
+           case FILE_OPADD:
                p->h += m->mask;
                /*@innerbreak@*/ break;
-           case OPMINUS:
+           case FILE_OPMINUS:
                p->h -= m->mask;
                /*@innerbreak@*/ break;
-           case OPMULTIPLY:
+           case FILE_OPMULTIPLY:
                p->h *= m->mask;
                /*@innerbreak@*/ break;
-           case OPDIVIDE:
+           case FILE_OPDIVIDE:
                p->h /= m->mask;
                /*@innerbreak@*/ break;
-           case OPMODULO:
+           case FILE_OPMODULO:
                p->h %= m->mask;
                /*@innerbreak@*/ break;
            }
-       if (m->mask_op & OPINVERSE)
+       if (m->mask_op & FILE_OPINVERSE)
            p->h = ~p->h;
        return 1;
-    case LONG:
-    case DATE:
-    case LDATE:
+    case FILE_LONG:
+    case FILE_DATE:
+    case FILE_LDATE:
        if (m->mask)
            switch (m->mask_op&0x7F) {
-           case OPAND:
+           case FILE_OPAND:
                p->l &= m->mask;
                /*@innerbreak@*/ break;
-           case OPOR:
+           case FILE_OPOR:
                p->l |= m->mask;
                /*@innerbreak@*/ break;
-           case OPXOR:
+           case FILE_OPXOR:
                p->l ^= m->mask;
                /*@innerbreak@*/ break;
-           case OPADD:
+           case FILE_OPADD:
                p->l += m->mask;
                /*@innerbreak@*/ break;
-           case OPMINUS:
+           case FILE_OPMINUS:
                p->l -= m->mask;
                /*@innerbreak@*/ break;
-           case OPMULTIPLY:
+           case FILE_OPMULTIPLY:
                p->l *= m->mask;
                /*@innerbreak@*/ break;
-           case OPDIVIDE:
+           case FILE_OPDIVIDE:
                p->l /= m->mask;
                /*@innerbreak@*/ break;
-           case OPMODULO:
+           case FILE_OPMODULO:
                p->l %= m->mask;
                /*@innerbreak@*/ break;
            }
-       if (m->mask_op & OPINVERSE)
+       if (m->mask_op & FILE_OPINVERSE)
            p->l = ~p->l;
        return 1;
-    case STRING:
+    case FILE_STRING:
        {
            int n;
 
@@ -239,7 +239,7 @@ fmagicSConvert(fmagic fm, struct magic *m)
                p->s[n] = '\0';
            return 1;
        }
-    case PSTRING:
+    case FILE_PSTRING:
        {
            char *ptr1 = p->s, *ptr2 = ptr1 + 1;
            int n = *p->s;
@@ -253,141 +253,141 @@ fmagicSConvert(fmagic fm, struct magic *m)
                p->s[n] = '\0';
            return 1;
        }
-    case BESHORT:
+    case FILE_BESHORT:
        p->h = (short)((p->hs[0]<<8)|(p->hs[1]));
        if (m->mask)
            switch (m->mask_op&0x7F) {
-           case OPAND:
+           case FILE_OPAND:
                p->h &= m->mask;
                /*@innerbreak@*/ break;
-           case OPOR:
+           case FILE_OPOR:
                p->h |= m->mask;
                /*@innerbreak@*/ break;
-           case OPXOR:
+           case FILE_OPXOR:
                p->h ^= m->mask;
                /*@innerbreak@*/ break;
-           case OPADD:
+           case FILE_OPADD:
                p->h += m->mask;
                /*@innerbreak@*/ break;
-           case OPMINUS:
+           case FILE_OPMINUS:
                p->h -= m->mask;
                /*@innerbreak@*/ break;
-           case OPMULTIPLY:
+           case FILE_OPMULTIPLY:
                p->h *= m->mask;
                /*@innerbreak@*/ break;
-           case OPDIVIDE:
+           case FILE_OPDIVIDE:
                p->h /= m->mask;
                /*@innerbreak@*/ break;
-           case OPMODULO:
+           case FILE_OPMODULO:
                p->h %= m->mask;
                /*@innerbreak@*/ break;
            }
-       if (m->mask_op & OPINVERSE)
+       if (m->mask_op & FILE_OPINVERSE)
            p->h = ~p->h;
        return 1;
-    case BELONG:
-    case BEDATE:
-    case BELDATE:
+    case FILE_BELONG:
+    case FILE_BEDATE:
+    case FILE_BELDATE:
        p->l = (int32_t)
            ((p->hl[0]<<24)|(p->hl[1]<<16)|(p->hl[2]<<8)|(p->hl[3]));
        if (m->mask)
            switch (m->mask_op&0x7F) {
-           case OPAND:
+           case FILE_OPAND:
                p->l &= m->mask;
                /*@innerbreak@*/ break;
-           case OPOR:
+           case FILE_OPOR:
                p->l |= m->mask;
                /*@innerbreak@*/ break;
-           case OPXOR:
+           case FILE_OPXOR:
                p->l ^= m->mask;
                /*@innerbreak@*/ break;
-           case OPADD:
+           case FILE_OPADD:
                p->l += m->mask;
                /*@innerbreak@*/ break;
-           case OPMINUS:
+           case FILE_OPMINUS:
                p->l -= m->mask;
                /*@innerbreak@*/ break;
-           case OPMULTIPLY:
+           case FILE_OPMULTIPLY:
                p->l *= m->mask;
                /*@innerbreak@*/ break;
-           case OPDIVIDE:
+           case FILE_OPDIVIDE:
                p->l /= m->mask;
                /*@innerbreak@*/ break;
-           case OPMODULO:
+           case FILE_OPMODULO:
                p->l %= m->mask;
                /*@innerbreak@*/ break;
            }
-       if (m->mask_op & OPINVERSE)
+       if (m->mask_op & FILE_OPINVERSE)
            p->l = ~p->l;
        return 1;
-    case LESHORT:
+    case FILE_LESHORT:
        p->h = (short)((p->hs[1]<<8)|(p->hs[0]));
        if (m->mask)
            switch (m->mask_op&0x7F) {
-           case OPAND:
+           case FILE_OPAND:
                p->h &= m->mask;
                /*@innerbreak@*/ break;
-           case OPOR:
+           case FILE_OPOR:
                p->h |= m->mask;
                /*@innerbreak@*/ break;
-           case OPXOR:
+           case FILE_OPXOR:
                p->h ^= m->mask;
                /*@innerbreak@*/ break;
-           case OPADD:
+           case FILE_OPADD:
                p->h += m->mask;
                /*@innerbreak@*/ break;
-           case OPMINUS:
+           case FILE_OPMINUS:
                p->h -= m->mask;
                /*@innerbreak@*/ break;
-           case OPMULTIPLY:
+           case FILE_OPMULTIPLY:
                p->h *= m->mask;
                /*@innerbreak@*/ break;
-           case OPDIVIDE:
+           case FILE_OPDIVIDE:
                p->h /= m->mask;
                /*@innerbreak@*/ break;
-           case OPMODULO:
+           case FILE_OPMODULO:
                p->h %= m->mask;
                /*@innerbreak@*/ break;
            }
-       if (m->mask_op & OPINVERSE)
+       if (m->mask_op & FILE_OPINVERSE)
            p->h = ~p->h;
        return 1;
-    case LELONG:
-    case LEDATE:
-    case LELDATE:
+    case FILE_LELONG:
+    case FILE_LEDATE:
+    case FILE_LELDATE:
        p->l = (int32_t)
            ((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0]));
        if (m->mask)
            switch (m->mask_op&0x7F) {
-           case OPAND:
+           case FILE_OPAND:
                p->l &= m->mask;
                /*@innerbreak@*/ break;
-           case OPOR:
+           case FILE_OPOR:
                p->l |= m->mask;
                /*@innerbreak@*/ break;
-           case OPXOR:
+           case FILE_OPXOR:
                p->l ^= m->mask;
                /*@innerbreak@*/ break;
-           case OPADD:
+           case FILE_OPADD:
                p->l += m->mask;
                /*@innerbreak@*/ break;
-           case OPMINUS:
+           case FILE_OPMINUS:
                p->l -= m->mask;
                /*@innerbreak@*/ break;
-           case OPMULTIPLY:
+           case FILE_OPMULTIPLY:
                p->l *= m->mask;
                /*@innerbreak@*/ break;
-           case OPDIVIDE:
+           case FILE_OPDIVIDE:
                p->l /= m->mask;
                /*@innerbreak@*/ break;
-           case OPMODULO:
+           case FILE_OPMODULO:
                p->l %= m->mask;
                /*@innerbreak@*/ break;
            }
-       if (m->mask_op & OPINVERSE)
+       if (m->mask_op & FILE_OPINVERSE)
            p->l = ~p->l;
        return 1;
-    case REGEX:
+    case FILE_REGEX:
        return 1;
     default:
        error(EXIT_FAILURE, 0, "invalid type %d in fmagicSConvert().\n", m->type);
@@ -399,12 +399,12 @@ fmagicSConvert(fmagic fm, struct magic *m)
 
 
 static void
-fmagicSDebug(int32_t offset, char *str, int len)
+fmagicSDebug(int32_t offset, char *str, size_t len)
        /*@globals fileSystem @*/
        /*@modifies fileSystem @*/
 {
     (void) fprintf(stderr, "fmagicSGet @%d: ", offset);
-    showstr(stderr, (char *) str, len);
+    file_showstr(stderr, (char *) str, len);
     (void) fputc('\n', stderr);
     (void) fputc('\n', stderr);
 }
@@ -421,7 +421,7 @@ fmagicSGet(fmagic fm, struct magic *m)
     int32_t offset = m->offset;
 
 /*@-branchstate@*/
-    if (m->type == REGEX) {
+    if (m->type == FILE_REGEX) {
        /*
        * offset is interpreted as last line to search,
        * (starting at 1), not as bytes-from start-of-file
@@ -450,270 +450,270 @@ fmagicSGet(fmagic fm, struct magic *m)
 
     if (fm->flags & FMAGIC_FLAGS_DEBUG) {
        fmagicSDebug(offset, (char *) p, sizeof(*p));
-       mdump(m);
+       file_mdump(m);
     }
 
     if (m->flag & INDIR) {
        switch (m->in_type) {
-       case BYTE:
+       case FILE_BYTE:
            if (m->in_offset)
                switch (m->in_op&0x7F) {
-               case OPAND:
+               case FILE_OPAND:
                    offset = p->b & m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPOR:
+               case FILE_OPOR:
                    offset = p->b | m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPXOR:
+               case FILE_OPXOR:
                    offset = p->b ^ m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPADD:
+               case FILE_OPADD:
                    offset = p->b + m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMINUS:
+               case FILE_OPMINUS:
                    offset = p->b - m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMULTIPLY:
+               case FILE_OPMULTIPLY:
                    offset = p->b * m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPDIVIDE:
+               case FILE_OPDIVIDE:
                    offset = p->b / m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMODULO:
+               case FILE_OPMODULO:
                    offset = p->b % m->in_offset;
                    /*@innerbreak@*/ break;
                }
-           if (m->in_op & OPINVERSE)
+           if (m->in_op & FILE_OPINVERSE)
                offset = ~offset;
            break;
-       case BESHORT:
+       case FILE_BESHORT:
            if (m->in_offset)
                switch (m->in_op&0x7F) {
-               case OPAND:
+               case FILE_OPAND:
                    offset = (short)((p->hs[0]<<8) | (p->hs[1])) &
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPOR:
+               case FILE_OPOR:
                    offset = (short)((p->hs[0]<<8) | (p->hs[1])) |
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPXOR:
+               case FILE_OPXOR:
                    offset = (short)((p->hs[0]<<8) | (p->hs[1])) ^
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPADD:
+               case FILE_OPADD:
                    offset = (short)((p->hs[0]<<8) | (p->hs[1])) +
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMINUS:
+               case FILE_OPMINUS:
                    offset = (short)((p->hs[0]<<8) | (p->hs[1])) -
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMULTIPLY:
+               case FILE_OPMULTIPLY:
                    offset = (short)((p->hs[0]<<8) | (p->hs[1])) *
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPDIVIDE:
+               case FILE_OPDIVIDE:
                    offset = (short)((p->hs[0]<<8) | (p->hs[1])) /
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMODULO:
+               case FILE_OPMODULO:
                    offset = (short)((p->hs[0]<<8) | (p->hs[1])) %
                                 m->in_offset;
                    /*@innerbreak@*/ break;
                }
-           if (m->in_op & OPINVERSE)
+           if (m->in_op & FILE_OPINVERSE)
                offset = ~offset;
            break;
-       case LESHORT:
+       case FILE_LESHORT:
            if (m->in_offset)
                switch (m->in_op&0x7F) {
-               case OPAND:
+               case FILE_OPAND:
                    offset = (short)((p->hs[1]<<8) | (p->hs[0])) &
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPOR:
+               case FILE_OPOR:
                    offset = (short)((p->hs[1]<<8) | (p->hs[0])) |
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPXOR:
+               case FILE_OPXOR:
                    offset = (short)((p->hs[1]<<8) | (p->hs[0])) ^
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPADD:
+               case FILE_OPADD:
                    offset = (short)((p->hs[1]<<8) | (p->hs[0])) +
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMINUS:
+               case FILE_OPMINUS:
                    offset = (short)((p->hs[1]<<8) | (p->hs[0])) -
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMULTIPLY:
+               case FILE_OPMULTIPLY:
                    offset = (short)((p->hs[1]<<8) | (p->hs[0])) *
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPDIVIDE:
+               case FILE_OPDIVIDE:
                    offset = (short)((p->hs[1]<<8) | (p->hs[0])) /
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMODULO:
+               case FILE_OPMODULO:
                    offset = (short)((p->hs[1]<<8) | (p->hs[0])) %
                                 m->in_offset;
                    /*@innerbreak@*/ break;
                }
-           if (m->in_op & OPINVERSE)
+           if (m->in_op & FILE_OPINVERSE)
                offset = ~offset;
            break;
-       case SHORT:
+       case FILE_SHORT:
            if (m->in_offset)
                switch (m->in_op&0x7F) {
-               case OPAND:
+               case FILE_OPAND:
                    offset = p->h & m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPOR:
+               case FILE_OPOR:
                    offset = p->h | m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPXOR:
+               case FILE_OPXOR:
                    offset = p->h ^ m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPADD:
+               case FILE_OPADD:
                    offset = p->h + m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMINUS:
+               case FILE_OPMINUS:
                    offset = p->h - m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMULTIPLY:
+               case FILE_OPMULTIPLY:
                    offset = p->h * m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPDIVIDE:
+               case FILE_OPDIVIDE:
                    offset = p->h / m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMODULO:
+               case FILE_OPMODULO:
                    offset = p->h % m->in_offset;
                    /*@innerbreak@*/ break;
                }
-           if (m->in_op & OPINVERSE)
+           if (m->in_op & FILE_OPINVERSE)
                offset = ~offset;
            break;
-       case BELONG:
+       case FILE_BELONG:
            if (m->in_offset)
                switch (m->in_op&0x7F) {
-               case OPAND:
+               case FILE_OPAND:
                    offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) |
                                        (p->hl[2]<< 8) | (p->hl[3])) &
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPOR:
+               case FILE_OPOR:
                    offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) |
                                        (p->hl[2]<< 8) | (p->hl[3])) |
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPXOR:
+               case FILE_OPXOR:
                    offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) |
                                        (p->hl[2]<< 8) | (p->hl[3])) ^
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPADD:
+               case FILE_OPADD:
                    offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) |
                                        (p->hl[2]<< 8) | (p->hl[3])) +
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMINUS:
+               case FILE_OPMINUS:
                    offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) |
                                        (p->hl[2]<< 8) | (p->hl[3])) -
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMULTIPLY:
+               case FILE_OPMULTIPLY:
                    offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) |
                                        (p->hl[2]<< 8) | (p->hl[3])) *
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPDIVIDE:
+               case FILE_OPDIVIDE:
                    offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) |
                                        (p->hl[2]<< 8) | (p->hl[3])) /
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMODULO:
+               case FILE_OPMODULO:
                    offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) |
                                        (p->hl[2]<< 8) | (p->hl[3])) %
                                 m->in_offset;
                    /*@innerbreak@*/ break;
                }
-           if (m->in_op & OPINVERSE)
+           if (m->in_op & FILE_OPINVERSE)
                offset = ~offset;
            break;
-       case LELONG:
+       case FILE_LELONG:
            if (m->in_offset)
                switch (m->in_op&0x7F) {
-               case OPAND:
+               case FILE_OPAND:
                    offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) |
                                        (p->hl[1]<< 8) | (p->hl[0])) &
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPOR:
+               case FILE_OPOR:
                    offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) |
                                        (p->hl[1]<< 8) | (p->hl[0])) |
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPXOR:
+               case FILE_OPXOR:
                    offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) |
                                        (p->hl[1]<< 8) | (p->hl[0])) ^
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPADD:
+               case FILE_OPADD:
                    offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) |
                                        (p->hl[1]<< 8) | (p->hl[0])) +
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMINUS:
+               case FILE_OPMINUS:
                    offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) |
                                        (p->hl[1]<< 8) | (p->hl[0])) -
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMULTIPLY:
+               case FILE_OPMULTIPLY:
                    offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) |
                                        (p->hl[1]<< 8) | (p->hl[0])) *
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPDIVIDE:
+               case FILE_OPDIVIDE:
                    offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) |
                                         (p->hl[1]<< 8) | (p->hl[0])) /
                                 m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMODULO:
+               case FILE_OPMODULO:
                    offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) |
                                        (p->hl[1]<< 8) | (p->hl[0])) %
                                 m->in_offset;
                    /*@innerbreak@*/ break;
                }
-           if (m->in_op & OPINVERSE)
+           if (m->in_op & FILE_OPINVERSE)
                offset = ~offset;
            break;
-       case LONG:
+       case FILE_LONG:
            if (m->in_offset)
                switch (m->in_op&0x7F) {
-               case OPAND:
+               case FILE_OPAND:
                    offset = p->l & m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPOR:
+               case FILE_OPOR:
                    offset = p->l | m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPXOR:
+               case FILE_OPXOR:
                    offset = p->l ^ m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPADD:
+               case FILE_OPADD:
                    offset = p->l + m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMINUS:
+               case FILE_OPMINUS:
                    offset = p->l - m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMULTIPLY:
+               case FILE_OPMULTIPLY:
                    offset = p->l * m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPDIVIDE:
+               case FILE_OPDIVIDE:
                    offset = p->l / m->in_offset;
                    /*@innerbreak@*/ break;
-               case OPMODULO:
+               case FILE_OPMODULO:
                    offset = p->l % m->in_offset;
                    /*@innerbreak@*/ break;
            /*  case TOOMANYSWITCHBLOCKS:
@@ -724,7 +724,7 @@ fmagicSGet(fmagic fm, struct magic *m)
             *      sleep;
             */
                }
-           if (m->in_op & OPINVERSE)
+           if (m->in_op & FILE_OPINVERSE)
                offset = ~offset;
            break;
        }
@@ -738,7 +738,7 @@ fmagicSGet(fmagic fm, struct magic *m)
 
        if (fm->flags & FMAGIC_FLAGS_DEBUG) {
            fmagicSDebug(offset, (char *) p, sizeof(*p));
-           mdump(m);
+           file_mdump(m);
        }
     }
 /*@-compmempass@*/
@@ -766,30 +766,30 @@ fmagicSCheck(const fmagic fm, struct magic *m)
     }
 
     switch (m->type) {
-    case BYTE:
+    case FILE_BYTE:
        v = p->b;
        break;
 
-    case SHORT:
-    case BESHORT:
-    case LESHORT:
+    case FILE_SHORT:
+    case FILE_BESHORT:
+    case FILE_LESHORT:
        v = p->h;
        break;
 
-    case LONG:
-    case BELONG:
-    case LELONG:
-    case DATE:
-    case BEDATE:
-    case LEDATE:
-    case LDATE:
-    case BELDATE:
-    case LELDATE:
+    case FILE_LONG:
+    case FILE_BELONG:
+    case FILE_LELONG:
+    case FILE_DATE:
+    case FILE_BEDATE:
+    case FILE_LEDATE:
+    case FILE_LDATE:
+    case FILE_BELDATE:
+    case FILE_LELDATE:
        v = p->l;
        break;
 
-    case STRING:
-    case PSTRING:
+    case FILE_STRING:
+    case FILE_PSTRING:
     {
        /*
         * What we want here is:
@@ -834,7 +834,7 @@ fmagicSCheck(const fmagic fm, struct magic *m)
        }
        break;
     }
-    case REGEX:
+    case FILE_REGEX:
     {
        int rc;
        regex_t rx;
@@ -857,8 +857,8 @@ fmagicSCheck(const fmagic fm, struct magic *m)
        return 0;
     }
 
-    if(m->type != STRING && m->type != PSTRING)
-       v = signextend(m, v);
+    if (m->type != FILE_STRING && m->type != FILE_PSTRING)
+       v = file_signextend(m, v);
 
     switch (m->reln) {
     case 'x':
@@ -987,7 +987,7 @@ fmagicSMatch(const fmagic fm)
 
        if (! firstline) { /* we found another match */
            /* put a newline and '-' to do some simple formatting */
-           fmagicPrintf(fm, "\n- ");
+           file_printf(fm, "\n- ");
        }
 
        if ((cont_level+1) >= tmplen) {
@@ -1027,7 +1027,7 @@ fmagicSMatch(const fmagic fm)
                if (need_separator
                   && (m->nospflag == 0) && (m->desc[0] != '\0'))
                {
-                   fmagicPrintf(fm, " ");
+                   file_printf(fm, " ");
                    need_separator = 0;
                }
                if ((cont_level+1) >= tmplen) {