1 /*
2  * file.private.h - definitions for file(1) program
3  * @(#)$Id: s.file.private.h 1.4 02/07/11 16:23:42-07:00 root@australia.pell.portland.or.us $
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 #ifndef _FILE_D
29 #define _FILE_D
30 
31 #define HOWMANY	8192		/* how much of the file to look at */
32 #define MAXMAGIS 1000		/* max entries in /etc/magic */
33 #define MAXDESC	50		/* max leng of text description */
34 #define MAXstring 32		/* max leng of "string" types */
35 
36 struct magic {
37 	short flag;
38 #define INDIR	1		/* if '>(...)' appears,  */
39 #define	UNSIGNED 2		/* comparison is unsigned */
40 	short cont_level;	/* level of ">" */
41 	struct {
42 		char type;	/* byte short long */
43 		long offset;	/* offset from indirection */
44 	} in;
45 	long offset;		/* offset to magic number */
46 	unsigned char reln;	/* relation (0=eq, '>'=gt, etc) */
47 	char type;		/* int, short, long or string. */
48 	char vallen;		/* length of string value, if any */
49 #define 			BYTE	1
50 #define				SHORT	2
51 #define				LONG	4
52 #define				STRING	5
53 #define				DATE	6
54 #define				BESHORT	7
55 #define				BELONG	8
56 #define				BEDATE	9
57 #define				LESHORT	10
58 #define				LELONG	11
59 #define				LEDATE	12
60 	union VALUETYPE {
61 		char s[MAXstring];
62 		unsigned char b;
63 		unsigned short h;
64 		unsigned long l;
65 		unsigned char hs[2];	/* 2 bytes of a fixed-endian "short" */
66 		unsigned char hl[4];	/* 2 bytes of a fixed-endian "long" */
67 	} value;		/* either number or string */
68 	unsigned long mask;	/* mask before comparison with value */
69 	char nospflag;		/* supress space character */
70 	char desc[MAXDESC];	/* description */
71 };
72 
73 #include <stdio.h>	/* Include that here, to make sure __P gets defined */
74 
75 #ifndef __P
76 # if __STDC__ || __cplusplus
77 #  define __P(a) a
78 # else
79 #  define __P(a) ()
80 #  define const
81 # endif
82 #endif
83 
84 extern int   apprentice			__P((char *, int));
85 extern int   __lf_ascmagic		__P((unsigned char *, int));
86 extern void  __lf_error			__P((const char *, ...));
87 extern void  __lf_ckfputs		__P((const char *, FILE *));
88 struct stat;
89 extern int   __lf_fsmagic		__P((const char *, struct stat *));
90 extern int   __lf_is_compress		__P((const unsigned char *, int *));
91 extern int   __lf_is_tar		__P((unsigned char *, int));
92 extern void  __lf_mdump			__P((struct magic *));
93 extern char* __lf_process		__P((const char *));
94 extern void  __lf_showstr		__P((FILE *, const char *, int));
95 extern int   __lf_softmagic		__P((unsigned char *, int));
96 extern void  __lf_tryit			__P((unsigned char *, int, int));
97 extern int   __lf_zmagic		__P((unsigned char *, int));
98 extern void  __lf_ckfprintf		__P((FILE *, const char *, ...));
99 extern void  __lf_form			__P((char *, ...));
100 extern unsigned long __lf_signextend	__P((struct magic *, unsigned long));
101 
102 
103 
104 extern int errno;		/* Some unixes don't define this..	*/
105 
106 extern char *progname;		/* the program name 			*/
107 extern char *__lf_magicfile;	/* name of the magic file		*/
108 extern int lineno;		/* current line number in magic file	*/
109 
110 extern struct magic *magic;	/* array of magic entries		*/
111 extern int nmagic;		/* number of valid magic[]s 		*/
112 
113 
114 extern int __lf_debug;		/* enable debugging?			*/
115 extern int __lf_zflag;		/* process compressed files?		*/
116 extern int __lf_lflag;		/* follow symbolic links?		*/
117 extern int __lf_emit_struct;	/* emit check output in structure __lf_form	*/
118 
119 #if !defined(__STDC__) || defined(sun) || defined(__sun__) || defined(__convex__)
120 extern int sys_nerr;
121 extern char *sys_errlist[];
122 #define strerror(e) \
123 	(((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
124 #endif
125 
126 #endif/*_FILE_D*/
127