xref: /openbsd/gnu/usr.sbin/mkhybrid/src/libfile/file.h (revision 68cbdb5e)
1 /*
2  * file.h - definitions for file(1) program
3  * @(#)$Id: file.h,v 1.2 2008/03/08 15:36:12 espie Exp $
4  *
5  * Copyright (c) Ian F. Darwin, 1987.
6  * Written by Ian F. Darwin.
7  *
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.
10  *
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:
14  *
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.
17  *
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.
21  *
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.
25  *
26  * 4. This notice may not be removed or altered.
27  */
28 
29 #ifndef __file_h__
30 #define __file_h__
31 
32 typedef int int32;
33 typedef unsigned int uint32;
34 
35 #ifndef HOWMANY
36 # define HOWMANY 8192		/* how much of the file to look at */
37 #endif
38 #define MAXMAGIS 1000		/* max entries in /etc/magic */
39 #define MAXDESC	50		/* max leng of text description */
40 #define MAXstring 32		/* max leng of "string" types */
41 
42 struct magic {
43 	short flag;
44 #define INDIR	1		/* if '>(...)' appears,  */
45 #define	UNSIGNED 2		/* comparison is unsigned */
46 #define ADD	4		/* if '>&' appears,  */
47 	short cont_level;	/* level of ">" */
48 	struct {
49 		char type;	/* byte short long */
50 		int32 offset;	/* offset from indirection */
51 	} in;
52 	int32 offset;		/* offset to magic number */
53 	unsigned char reln;	/* relation (0=eq, '>'=gt, etc) */
54 	char type;		/* int, short, long or string. */
55 	char vallen;		/* length of string value, if any */
56 #define 			BYTE	1
57 #define				SHORT	2
58 #define				LONG	4
59 #define				STRING	5
60 #define				DATE	6
61 #define				BESHORT	7
62 #define				BELONG	8
63 #define				BEDATE	9
64 #define				LESHORT	10
65 #define				LELONG	11
66 #define				LEDATE	12
67 	union VALUETYPE {
68 		unsigned char b;
69 		unsigned short h;
70 		uint32 l;
71 		char s[MAXstring];
72 		unsigned char hs[2];	/* 2 bytes of a fixed-endian "short" */
73 		unsigned char hl[4];	/* 2 bytes of a fixed-endian "long" */
74 	} value;		/* either number or string */
75 	uint32 mask;	/* mask before comparison with value */
76 	char nospflag;		/* supress space character */
77 	char desc[MAXDESC];	/* description */
78 };
79 
80 #include <stdio.h>	/* Include that here, to make sure __P gets defined */
81 
82 #ifndef __P
83 # if __STDC__ || __cplusplus
84 #  define __P(a) a
85 # else
86 #  define __P(a) ()
87 #  define const
88 # endif
89 #endif
90 
91 extern int   ascmagic		__P((unsigned char *, int));
92 extern void  error		__P((const char *, ...));
93 extern void  ckfputs		__P((const char *, FILE *));
94 struct stat;
95 extern int   fsmagic		__P((const char *, struct stat *));
96 extern int   is_compress	__P((const unsigned char *, int *));
97 extern int   is_tar		__P((unsigned char *, int));
98 extern void  magwarn		__P((const char *, ...));
99 extern void  mdump		__P((struct magic *));
100 extern char *get_magic_magic	__P((const char *));
101 extern void  showstr		__P((FILE *, const char *, int));
102 extern char *softmagic		__P((unsigned char *, int));
103 extern int   tryit		__P((unsigned char *, int, int));
104 extern int   zmagic		__P((unsigned char *, int));
105 extern void  ckfprintf		__P((FILE *, const char *, ...));
106 extern uint32 signextend	__P((struct magic *, unsigned int32));
107 extern int internatmagic	__P((unsigned char *, int));
108 extern void tryelf		__P((int, char *, int));
109 
110 
111 extern int errno;		/* Some unixes don't define this..	*/
112 
113 extern char *progname;		/* the program name 			*/
114 extern char *magicfile;		/* name of the magic file		*/
115 extern int lineno;		/* current line number in magic file	*/
116 
117 extern struct magic *magic;	/* array of magic entries		*/
118 extern int nmagic;		/* number of valid magic[]s 		*/
119 
120 
121 extern int debug;		/* enable debugging?			*/
122 extern int zflag;		/* process compressed files?		*/
123 extern int lflag;		/* follow symbolic links?		*/
124 
125 extern int optind;		/* From getopt(3)			*/
126 extern char *optarg;
127 
128 #if defined(sun) || defined(__sun__) || defined (__sun)
129 # if defined(__svr4) || defined (__SVR4) || defined(__svr4__)
130 #  define SOLARIS
131 # else
132 #  define SUNOS
133 # endif
134 #endif
135 
136 
137 #if !defined(__STDC__) || defined(SUNOS) || defined(__convex__)
138 extern int sys_nerr;
139 extern char *sys_errlist[];
140 #define strerror(e) \
141 	(((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
142 #define strtoul(a, b, c)	strtol(a, b, c)
143 #endif
144 
145 #ifndef MAXPATHLEN
146 #define	MAXPATHLEN	512
147 #endif
148 
149 #endif /* __file_h__ */
150