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