xref: /openbsd/usr.bin/file/file.h (revision 78b63d65)
1 /*	$OpenBSD: file.h,v 1.7 1999/09/26 20:47:28 ian Exp $	*/
2 
3 /*
4  * file.h - definitions for file(1) program
5  *
6  * Copyright (c) Ian F. Darwin, 1987.
7  * Written by Ian F. Darwin.
8  *
9  * This software is not subject to any license of the American Telephone
10  * and Telegraph Company or of the Regents of the University of California.
11  *
12  * Permission is granted to anyone to use this software for any purpose on
13  * any computer system, and to alter it and redistribute it freely, subject
14  * to the following restrictions:
15  *
16  * 1. The author is not responsible for the consequences of use of this
17  *    software, no matter how awful, even if they arise from flaws in it.
18  *
19  * 2. The origin of this software must not be misrepresented, either by
20  *    explicit claim or by omission.  Since few users ever read sources,
21  *    credits must appear in the documentation.
22  *
23  * 3. Altered versions must be plainly marked as such, and must not be
24  *    misrepresented as being the original software.  Since few users
25  *    ever read sources, credits must appear in the documentation.
26  *
27  * 4. This notice may not be removed or altered.
28  */
29 
30 #ifndef __file_h__
31 #define __file_h__
32 
33 typedef int8_t int8;
34 typedef int32_t int32;
35 typedef u_int32_t uint32;
36 
37 #ifndef HOWMANY
38 # define HOWMANY 8192		/* how much of the file to look at */
39 #endif
40 #define MAXMAGIS 5000		/* max entries in /etc/magic */
41 #define MAXDESC	50		/* max leng of text description */
42 #define MAXstring 32		/* max leng of "string" types */
43 
44 struct magic {
45 	short flag;
46 #define INDIR	1		/* if '>(...)' appears,  */
47 #define	UNSIGNED 2		/* comparison is unsigned */
48 #define ADD	4		/* if '>&' appears,  */
49 	short cont_level;	/* level of ">" */
50 	struct {
51 		int8 type;	/* byte short long */
52 		int32 offset;	/* offset from indirection */
53 	} in;
54 	int32 offset;		/* offset to magic number */
55 	unsigned char reln;	/* relation (0=eq, '>'=gt, etc) */
56 	int8 type;		/* int, short, long or string. */
57 	char vallen;		/* length of string value, if any */
58 #define 			BYTE	1
59 #define				SHORT	2
60 #define				LONG	4
61 #define				STRING	5
62 #define				DATE	6
63 #define				BESHORT	7
64 #define				BELONG	8
65 #define				BEDATE	9
66 #define				LESHORT	10
67 #define				LELONG	11
68 #define				LEDATE	12
69 	union VALUETYPE {
70 		unsigned char b;
71 		unsigned short h;
72 		uint32 l;
73 		char s[MAXstring];
74 		unsigned char hs[2];	/* 2 bytes of a fixed-endian "short" */
75 		unsigned char hl[4];	/* 2 bytes of a fixed-endian "long" */
76 	} value;		/* either number or string */
77 	uint32 mask;	/* mask before comparison with value */
78 	char nospflag;		/* supress space character */
79 	char desc[MAXDESC];	/* description */
80 };
81 
82 #include <stdio.h>	/* Include that here, to make sure __P gets defined */
83 
84 #ifndef __P
85 # ifdef __STDC__ || __cplusplus
86 #  define __P(a) a
87 # else
88 #  define __P(a) ()
89 #  define const
90 # endif
91 #endif
92 
93 extern int   apprentice		__P((char *, int));
94 extern int   ascmagic		__P((unsigned char *, int));
95 extern void  ckfputs		__P((const char *, FILE *));
96 struct stat;
97 extern int   fsmagic		__P((const char *, struct stat *));
98 extern int   is_compress	__P((const unsigned char *, int *));
99 extern int   is_tar		__P((unsigned char *, int));
100 extern void  mdump		__P((struct magic *));
101 extern void  process		__P((const char *, int));
102 extern void  showstr		__P((FILE *, const char *, int));
103 extern int   softmagic		__P((unsigned char *, int));
104 extern int   tryit		__P((unsigned char *, int, int));
105 extern int   zmagic		__P((unsigned char *, int));
106 extern void  ckfprintf		__P((FILE *, const char *, ...));
107 extern uint32 signextend	__P((struct magic *, unsigned int32));
108 extern int internatmagic	__P((unsigned char *, int));
109 extern void tryelf		__P((int, char *, int));
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 
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__)
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
149 
150 #endif /* __file_h__ */
151