[BACK]Return to file.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / file

Annotation of src/usr.bin/file/file.h, Revision 1.12

1.12    ! ian         1: /*     $OpenBSD: file.h,v 1.11 2003/03/03 22:24:08 ian Exp $   */
1.3       millert     2:
1.1       deraadt     3: /*
                      4:  * file.h - definitions for file(1) program
                      5:  *
1.12    ! ian         6:  * Copyright (c) Ian F. Darwin 1986-1995.
        !             7:  * Software written by Ian F. Darwin and others;
        !             8:  * maintained 1995-present by Christos Zoulas and others.
        !             9:  *
        !            10:  * Redistribution and use in source and binary forms, with or without
        !            11:  * modification, are permitted provided that the following conditions
        !            12:  * are met:
        !            13:  * 1. Redistributions of source code must retain the above copyright
        !            14:  *    notice immediately at the beginning of the file, without modification,
        !            15:  *    this list of conditions, and the following disclaimer.
        !            16:  * 2. Redistributions in binary form must reproduce the above copyright
        !            17:  *    notice, this list of conditions and the following disclaimer in the
        !            18:  *    documentation and/or other materials provided with the distribution.
        !            19:  * 3. All advertising materials mentioning features or use of this software
        !            20:  *    must display the following acknowledgement:
        !            21:  *    This product includes software developed by Ian F. Darwin and others.
        !            22:  * 4. The name of the author may not be used to endorse or promote products
        !            23:  *    derived from this software without specific prior written permission.
        !            24:  *
        !            25:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
        !            26:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            27:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            28:  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
        !            29:  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            30:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            31:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            32:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            33:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            34:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            35:  * SUCH DAMAGE.
1.1       deraadt    36:  */
                     37:
1.3       millert    38: #ifndef __file_h__
                     39: #define __file_h__
                     40:
1.11      ian        41: #ifdef HAVE_CONFIG_H
                     42: #include "config.h"
                     43: #endif
                     44:
                     45: #include <errno.h>
                     46: #include <stdio.h>
                     47: #ifdef HAVE_STDINT_H
                     48: #include <stdint.h>
                     49: #elif defined(HAVE_INTTYPES_H)
                     50: #include <inttypes.h>
                     51: #endif
                     52:
1.1       deraadt    53: #ifndef HOWMANY
                     54: # define HOWMANY 8192          /* how much of the file to look at */
                     55: #endif
1.7       ian        56: #define MAXMAGIS 5000          /* max entries in /etc/magic */
1.1       deraadt    57: #define MAXDESC        50              /* max leng of text description */
                     58: #define MAXstring 32           /* max leng of "string" types */
                     59:
                     60: struct magic {
                     61:        short flag;
                     62: #define INDIR  1               /* if '>(...)' appears,  */
                     63: #define        UNSIGNED 2              /* comparison is unsigned */
1.3       millert    64: #define ADD    4               /* if '>&' appears,  */
1.1       deraadt    65:        short cont_level;       /* level of ">" */
                     66:        struct {
1.10      itojun     67:                int8_t type;    /* byte short long */
                     68:                int32_t offset; /* offset from indirection */
1.1       deraadt    69:        } in;
1.10      itojun     70:        int32_t offset;         /* offset to magic number */
1.1       deraadt    71:        unsigned char reln;     /* relation (0=eq, '>'=gt, etc) */
1.10      itojun     72:        int8_t type;            /* int, short, long or string. */
1.1       deraadt    73:        char vallen;            /* length of string value, if any */
                     74: #define                        BYTE    1
                     75: #define                                SHORT   2
                     76: #define                                LONG    4
                     77: #define                                STRING  5
                     78: #define                                DATE    6
                     79: #define                                BESHORT 7
                     80: #define                                BELONG  8
                     81: #define                                BEDATE  9
                     82: #define                                LESHORT 10
                     83: #define                                LELONG  11
                     84: #define                                LEDATE  12
                     85:        union VALUETYPE {
                     86:                unsigned char b;
                     87:                unsigned short h;
1.10      itojun     88:                uint32_t l;
1.1       deraadt    89:                char s[MAXstring];
                     90:                unsigned char hs[2];    /* 2 bytes of a fixed-endian "short" */
                     91:                unsigned char hl[4];    /* 2 bytes of a fixed-endian "long" */
                     92:        } value;                /* either number or string */
1.10      itojun     93:        uint32_t mask;  /* mask before comparison with value */
1.1       deraadt    94:        char nospflag;          /* supress space character */
                     95:        char desc[MAXDESC];     /* description */
                     96: };
                     97:
1.8       millert    98: extern int   apprentice(char *, int);
                     99: extern int   ascmagic(unsigned char *, int);
                    100: extern void  ckfputs(const char *, FILE *);
1.1       deraadt   101: struct stat;
1.8       millert   102: extern int   fsmagic(const char *, struct stat *);
                    103: extern int   is_compress(const unsigned char *, int *);
                    104: extern int   is_tar(unsigned char *, int);
                    105: extern void  mdump(struct magic *);
                    106: extern void  process(const char *, int);
                    107: extern void  showstr(FILE *, const char *, int);
                    108: extern int   softmagic(unsigned char *, int);
                    109: extern int   tryit(unsigned char *, int, int);
                    110: extern int   zmagic(unsigned char *, int);
                    111: extern void  ckfprintf(FILE *, const char *, ...);
1.10      itojun    112: extern uint32_t signextend(struct magic *, uint32_t);
1.8       millert   113: extern int internatmagic(unsigned char *, int);
1.11      ian       114: extern void tryelf(int, unsigned char *, int);
1.1       deraadt   115:
                    116:
                    117: extern int errno;              /* Some unixes don't define this..      */
                    118:
                    119: extern char *progname;         /* the program name                     */
                    120: extern char *magicfile;                /* name of the magic file               */
                    121: extern int lineno;             /* current line number in magic file    */
                    122:
                    123: extern struct magic *magic;    /* array of magic entries               */
                    124: extern int nmagic;             /* number of valid magic[]s             */
                    125:
                    126:
                    127: extern int debug;              /* enable debugging?                    */
                    128: extern int zflag;              /* process compressed files?            */
                    129: extern int lflag;              /* follow symbolic links?               */
                    130:
                    131: extern int optind;             /* From getopt(3)                       */
                    132: extern char *optarg;
                    133:
1.3       millert   134: #if defined(sun) || defined(__sun__) || defined (__sun)
                    135: # if defined(__svr4) || defined (__SVR4) || defined(__svr4__)
                    136: #  define SOLARIS
                    137: # else
                    138: #  define SUNOS
                    139: # endif
                    140: #endif
                    141:
                    142:
                    143: #if !defined(__STDC__) || defined(SUNOS) || defined(__convex__)
1.1       deraadt   144: extern int sys_nerr;
                    145: extern char *sys_errlist[];
                    146: #define strerror(e) \
                    147:        (((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
                    148: #define strtoul(a, b, c)       strtol(a, b, c)
                    149: #endif
                    150:
                    151: #ifndef MAXPATHLEN
                    152: #define        MAXPATHLEN      512
                    153: #endif
1.3       millert   154:
                    155: #endif /* __file_h__ */