file_cmds-60.tar.gz
[apple/file_cmds.git] / file / file.h
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 /* $OpenBSD: file.h,v 1.3 1997/02/09 23:58:23 millert Exp $ */
25
26 /*
27 * file.h - definitions for file(1) program
28 *
29 * Copyright (c) Ian F. Darwin, 1987.
30 * Written by Ian F. Darwin.
31 *
32 * This software is not subject to any license of the American Telephone
33 * and Telegraph Company or of the Regents of the University of California.
34 *
35 * Permission is granted to anyone to use this software for any purpose on
36 * any computer system, and to alter it and redistribute it freely, subject
37 * to the following restrictions:
38 *
39 * 1. The author is not responsible for the consequences of use of this
40 * software, no matter how awful, even if they arise from flaws in it.
41 *
42 * 2. The origin of this software must not be misrepresented, either by
43 * explicit claim or by omission. Since few users ever read sources,
44 * credits must appear in the documentation.
45 *
46 * 3. Altered versions must be plainly marked as such, and must not be
47 * misrepresented as being the original software. Since few users
48 * ever read sources, credits must appear in the documentation.
49 *
50 * 4. This notice may not be removed or altered.
51 */
52
53 #ifndef __file_h__
54 #define __file_h__
55
56 typedef int32_t int32;
57 typedef u_int32_t uint32;
58
59 #ifndef HOWMANY
60 # define HOWMANY 8192 /* how much of the file to look at */
61 #endif
62 #define MAXMAGIS 1000 /* max entries in /etc/magic */
63 #define MAXDESC 50 /* max leng of text description */
64 #define MAXstring 32 /* max leng of "string" types */
65
66 struct magic {
67 short flag;
68 #define INDIR 1 /* if '>(...)' appears, */
69 #define UNSIGNED 2 /* comparison is unsigned */
70 #define ADD 4 /* if '>&' appears, */
71 short cont_level; /* level of ">" */
72 struct {
73 char type; /* byte short long */
74 int32 offset; /* offset from indirection */
75 } in;
76 int32 offset; /* offset to magic number */
77 unsigned char reln; /* relation (0=eq, '>'=gt, etc) */
78 char type; /* int, short, long or string. */
79 char vallen; /* length of string value, if any */
80 #define BYTE 1
81 #define SHORT 2
82 #define LONG 4
83 #define STRING 5
84 #define DATE 6
85 #define BESHORT 7
86 #define BELONG 8
87 #define BEDATE 9
88 #define LESHORT 10
89 #define LELONG 11
90 #define LEDATE 12
91 union VALUETYPE {
92 unsigned char b;
93 unsigned short h;
94 uint32 l;
95 char s[MAXstring];
96 unsigned char hs[2]; /* 2 bytes of a fixed-endian "short" */
97 unsigned char hl[4]; /* 2 bytes of a fixed-endian "long" */
98 } value; /* either number or string */
99 uint32 mask; /* mask before comparison with value */
100 char nospflag; /* supress space character */
101 char desc[MAXDESC]; /* description */
102 };
103
104 #include <stdio.h> /* Include that here, to make sure __P gets defined */
105
106 #ifndef __P
107 # if __STDC__ || __cplusplus
108 # define __P(a) a
109 # else
110 # define __P(a) ()
111 # define const
112 # endif
113 #endif
114
115 extern int apprentice __P((char *, int));
116 extern int ascmagic __P((unsigned char *, int));
117 extern void error __P((const char *, ...));
118 extern void ckfputs __P((const char *, FILE *));
119 struct stat;
120 extern int fsmagic __P((const char *, struct stat *));
121 extern int is_compress __P((const unsigned char *, int *));
122 extern int is_tar __P((unsigned char *, int));
123 extern void magwarn __P((const char *, ...));
124 extern void mdump __P((struct magic *));
125 extern void process __P((const char *, int));
126 extern void showstr __P((FILE *, const char *, int));
127 extern int softmagic __P((unsigned char *, int));
128 extern int tryit __P((unsigned char *, int, int));
129 extern int zmagic __P((unsigned char *, int));
130 extern void ckfprintf __P((FILE *, const char *, ...));
131 extern uint32 signextend __P((struct magic *, unsigned int32));
132 extern int internatmagic __P((unsigned char *, int));
133 extern void tryelf __P((int, char *, int));
134 extern void tryfat __P((const char *, int, char *, int));
135
136
137 extern int errno; /* Some unixes don't define this.. */
138
139 extern char *progname; /* the program name */
140 extern char *magicfile; /* name of the magic file */
141 extern int lineno; /* current line number in magic file */
142
143 extern struct magic *magic; /* array of magic entries */
144 extern int nmagic; /* number of valid magic[]s */
145
146
147 extern int debug; /* enable debugging? */
148 extern int zflag; /* process compressed files? */
149 extern int lflag; /* follow symbolic links? */
150
151 extern int optind; /* From getopt(3) */
152 extern char *optarg;
153
154 #if defined(sun) || defined(__sun__) || defined (__sun)
155 # if defined(__svr4) || defined (__SVR4) || defined(__svr4__)
156 # define SOLARIS
157 # else
158 # define SUNOS
159 # endif
160 #endif
161
162
163 #if !defined(__STDC__) || defined(SUNOS) || defined(__convex__)
164 extern int sys_nerr;
165 extern char *sys_errlist[];
166 #define strerror(e) \
167 (((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
168 #define strtoul(a, b, c) strtol(a, b, c)
169 #endif
170
171 #ifndef MAXPATHLEN
172 #define MAXPATHLEN 512
173 #endif
174
175 #endif /* __file_h__ */