file.h revision 68349
1/* 2 * file.h - definitions for file(1) program 3 * @(#)$Id: file.h,v 1.32 2000/05/14 22:58:53 christos 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#ifdef HAVE_CONFIG_H 33#include <config.h> 34#endif 35 36typedef int int32; 37typedef unsigned int uint32; 38 39#ifndef HOWMANY 40# define HOWMANY 16384 /* how much of the file to look at */ 41#endif 42#define MAXMAGIS 1000 /* max entries in /etc/magic */ 43#define MAXDESC 50 /* max leng of text description */ 44#define MAXstring 32 /* max leng of "string" types */ 45 46struct magic { 47 short flag; 48#define INDIR 1 /* if '>(...)' appears, */ 49#define UNSIGNED 2 /* comparison is unsigned */ 50#define ADD 4 /* if '>&' appears, */ 51 short cont_level; /* level of ">" */ 52 struct { 53 unsigned char type; /* byte short long */ 54 int32 offset; /* offset from indirection */ 55 } in; 56 int32 offset; /* offset to magic number */ 57 unsigned char reln; /* relation (0=eq, '>'=gt, etc) */ 58 unsigned char type; /* int, short, long or string. */ 59 char vallen; /* length of string value, if any */ 60#define BYTE 1 61#define SHORT 2 62#define LONG 4 63#define STRING 5 64#define DATE 6 65#define BESHORT 7 66#define BELONG 8 67#define BEDATE 9 68#define LESHORT 10 69#define LELONG 11 70#define LEDATE 12 71 union VALUETYPE { 72 unsigned char b; 73 unsigned short h; 74 uint32 l; 75 char s[MAXstring]; 76 unsigned char hs[2]; /* 2 bytes of a fixed-endian "short" */ 77 unsigned char hl[4]; /* 2 bytes of a fixed-endian "long" */ 78 } value; /* either number or string */ 79 uint32 mask; /* mask before comparison with value */ 80 char nospflag; /* supress space character */ 81 char desc[MAXDESC]; /* description */ 82}; 83 84#define BIT(A) (1 << (A)) 85#define STRING_IGNORE_LOWERCASE BIT(0) 86#define STRING_COMPACT_BLANK BIT(1) 87#define STRING_COMPACT_OPTIONAL_BLANK BIT(2) 88#define CHAR_IGNORE_LOWERCASE 'c' 89#define CHAR_COMPACT_BLANK 'B' 90#define CHAR_COMPACT_OPTIONAL_BLANK 'b' 91 92 93#include <stdio.h> /* Include that here, to make sure __P gets defined */ 94#include <errno.h> 95 96#ifndef __P 97# if defined(__STDC__) || defined(__cplusplus) 98# define __P(a) a 99# else 100# define __P(a) () 101# define const 102# endif 103#endif 104 105extern int apprentice __P((const char *, int)); 106extern int ascmagic __P((unsigned char *, int)); 107extern void error __P((const char *, ...)); 108extern void ckfputs __P((const char *, FILE *)); 109struct stat; 110extern int fsmagic __P((const char *, struct stat *)); 111extern int is_compress __P((const unsigned char *, int *)); 112extern int is_tar __P((unsigned char *, int)); 113extern void magwarn __P((const char *, ...)); 114extern void mdump __P((struct magic *)); 115extern void process __P((const char *, int)); 116extern void showstr __P((FILE *, const char *, int)); 117extern int softmagic __P((unsigned char *, int)); 118extern int tryit __P((unsigned char *, int, int)); 119extern int zmagic __P((unsigned char *, int)); 120extern void ckfprintf __P((FILE *, const char *, ...)); 121extern uint32 signextend __P((struct magic *, unsigned int32)); 122extern int internatmagic __P((unsigned char *, int)); 123extern void tryelf __P((int, unsigned char *, int)); 124 125extern char *progname; /* the program name */ 126extern const char *magicfile; /* name of the magic file */ 127extern int lineno; /* current line number in magic file */ 128 129extern struct magic *magic; /* array of magic entries */ 130extern int nmagic; /* number of valid magic[]s */ 131 132 133extern int debug; /* enable debugging? */ 134extern int zflag; /* process compressed files? */ 135extern int lflag; /* follow symbolic links? */ 136extern int sflag; /* read/analyze block special files? */ 137extern int iflag; /* Output types as mime-types */ 138 139extern int optind; /* From getopt(3) */ 140extern char *optarg; 141 142#ifndef HAVE_STRERROR 143extern int sys_nerr; 144extern char *sys_errlist[]; 145#define strerror(e) \ 146 (((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error") 147#endif 148 149#ifndef HAVE_STRTOUL 150#define strtoul(a, b, c) strtol(a, b, c) 151#endif 152 153#ifdef __STDC__ 154#define FILE_RCSID(id) \ 155static const char *rcsid(const char *p) { \ 156 return rcsid(p = id); \ 157} 158#else 159#define FILE_RCSID(id) static char *rcsid[] = id; 160#endif 161 162#endif /* __file_h__ */ 163