2 * file.h - definitions for file(1) program
3 * @(#)$Id: file.h,v 1.43 2002/07/03 18:57:52 christos Exp $
5 * Copyright (c) Ian F. Darwin, 1987.
6 * Written by Ian F. Darwin.
8 * This software is not subject to any license of the American Telephone
9 * and Telegraph Company or of the Regents of the University of California.
11 * Permission is granted to anyone to use this software for any purpose on
12 * any computer system, and to alter it and redistribute it freely, subject
13 * to the following restrictions:
15 * 1. The author is not responsible for the consequences of use of this
16 * software, no matter how awful, even if they arise from flaws in it.
18 * 2. The origin of this software must not be misrepresented, either by
19 * explicit claim or by omission. Since few users ever read sources,
20 * credits must appear in the documentation.
22 * 3. Altered versions must be plainly marked as such, and must not be
23 * misrepresented as being the original software. Since few users
24 * ever read sources, credits must appear in the documentation.
26 * 4. This notice may not be removed or altered.
33 #define _LARGEFILE_SOURCE
34 #define _LARGEFILE64_SOURCE
35 #define _FILE_OFFSET_BITS 64
47 /* Do this here and now, because struct stat gets re-defined on solaris */
51 # define HOWMANY 65536 /* how much of the file to look at */
53 #define MAXMAGIS 4096 /* max entries in /etc/magic */
54 #define MAXDESC 50 /* max leng of text description */
55 #define MAXstring 32 /* max leng of "string" types */
57 #define MAGICNO 0xF11E041C
64 uint16_t cont_level; /* level of ">" */
65 uint8_t nospflag; /* supress space character */
67 #define INDIR 1 /* if '>(...)' appears, */
68 #define UNSIGNED 2 /* comparison is unsigned */
69 #define OFFADD 4 /* if '>&' appears, */
70 uint8_t reln; /* relation (0=eq, '>'=gt, etc) */
71 uint8_t vallen; /* length of string value, if any */
72 uint8_t type; /* int, short, long or string. */
73 uint8_t in_type; /* type of indirrection */
90 uint8_t in_op; /* operator for indirection */
91 uint8_t mask_op; /* operator for mask */
100 #define OPINVERSE 0x80
101 int32_t offset; /* offset to magic number */
102 int32_t in_offset; /* offset from indirection */
109 uint8_t hs[2]; /* 2 bytes of a fixed-endian "short" */
110 uint8_t hl[4]; /* 4 bytes of a fixed-endian "long" */
111 } value; /* either number or string */
112 uint32_t mask; /* mask before comparison with value */
113 char desc[MAXDESC]; /* description */
114 } __attribute__((__packed__));
116 #define BIT(A) (1 << (A))
117 #define STRING_IGNORE_LOWERCASE BIT(0)
118 #define STRING_COMPACT_BLANK BIT(1)
119 #define STRING_COMPACT_OPTIONAL_BLANK BIT(2)
120 #define CHAR_IGNORE_LOWERCASE 'c'
121 #define CHAR_COMPACT_BLANK 'B'
122 #define CHAR_COMPACT_OPTIONAL_BLANK 'b'
125 /* list of magic entries */
127 struct magic *magic; /* array of magic entries */
128 uint32_t nmagic; /* number of entries in array */
129 struct mlist *next, *prev;
132 extern int apprentice(const char *, int);
133 extern int ascmagic(unsigned char *, int);
134 extern void error(const char *, ...);
135 extern void ckfputs(const char *, FILE *);
137 extern int fsmagic(const char *, struct stat *);
138 extern char *fmttime(long, int);
139 extern int is_compress(const unsigned char *, int *);
140 extern int is_tar(unsigned char *, int);
141 extern void magwarn(const char *, ...);
142 extern void mdump(struct magic *);
143 extern void process(const char *, int);
144 extern void showstr(FILE *, const char *, int);
145 extern int softmagic(unsigned char *, int);
146 extern int tryit(const char *, unsigned char *, int, int);
147 extern int zmagic(const char *, unsigned char *, int);
148 extern void ckfprintf(FILE *, const char *, ...);
149 extern uint32_t signextend(struct magic *, unsigned int32);
150 extern void tryelf(int, unsigned char *, int);
151 extern int pipe2file(int, void *, size_t);
154 extern char *progname; /* the program name */
155 extern const char *magicfile; /* name of the magic file */
156 extern int lineno; /* current line number in magic file */
158 extern struct mlist mlist; /* list of arrays of magic entries */
160 extern int debug; /* enable debugging? */
161 extern int zflag; /* process compressed files? */
162 extern int lflag; /* follow symbolic links? */
163 extern int sflag; /* read/analyze block special files? */
164 extern int iflag; /* Output types as mime-types */
167 extern int optind; /* From getopt(3) */
171 #ifndef HAVE_STRERROR
173 extern char *sys_errlist[];
174 #define strerror(e) \
175 (((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
179 #define strtoul(a, b, c) strtol(a, b, c)
182 #if defined(HAVE_MMAP) && defined(HAVE_SYS_MMAN_H) && !defined(QUICK)
186 #define FILE_RCSID(id) \
187 static const char *rcsid(const char *p) { \
188 return rcsid(p = id); \
191 #endif /* __file_h__ */