Annotation of src/usr.bin/file/file.h, Revision 1.11
1.11 ! ian 1: /* $OpenBSD: file.h,v 1.10 2002/06/05 13:46:44 itojun Exp $ */
1.3 millert 2:
1.1 deraadt 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:
1.3 millert 30: #ifndef __file_h__
31: #define __file_h__
32:
1.11 ! ian 33: #ifdef HAVE_CONFIG_H
! 34: #include "config.h"
! 35: #endif
! 36:
! 37: #include <errno.h>
! 38: #include <stdio.h>
! 39: #ifdef HAVE_STDINT_H
! 40: #include <stdint.h>
! 41: #elif defined(HAVE_INTTYPES_H)
! 42: #include <inttypes.h>
! 43: #endif
! 44:
1.1 deraadt 45: #ifndef HOWMANY
46: # define HOWMANY 8192 /* how much of the file to look at */
47: #endif
1.7 ian 48: #define MAXMAGIS 5000 /* max entries in /etc/magic */
1.1 deraadt 49: #define MAXDESC 50 /* max leng of text description */
50: #define MAXstring 32 /* max leng of "string" types */
51:
52: struct magic {
53: short flag;
54: #define INDIR 1 /* if '>(...)' appears, */
55: #define UNSIGNED 2 /* comparison is unsigned */
1.3 millert 56: #define ADD 4 /* if '>&' appears, */
1.1 deraadt 57: short cont_level; /* level of ">" */
58: struct {
1.10 itojun 59: int8_t type; /* byte short long */
60: int32_t offset; /* offset from indirection */
1.1 deraadt 61: } in;
1.10 itojun 62: int32_t offset; /* offset to magic number */
1.1 deraadt 63: unsigned char reln; /* relation (0=eq, '>'=gt, etc) */
1.10 itojun 64: int8_t type; /* int, short, long or string. */
1.1 deraadt 65: char vallen; /* length of string value, if any */
66: #define BYTE 1
67: #define SHORT 2
68: #define LONG 4
69: #define STRING 5
70: #define DATE 6
71: #define BESHORT 7
72: #define BELONG 8
73: #define BEDATE 9
74: #define LESHORT 10
75: #define LELONG 11
76: #define LEDATE 12
77: union VALUETYPE {
78: unsigned char b;
79: unsigned short h;
1.10 itojun 80: uint32_t l;
1.1 deraadt 81: char s[MAXstring];
82: unsigned char hs[2]; /* 2 bytes of a fixed-endian "short" */
83: unsigned char hl[4]; /* 2 bytes of a fixed-endian "long" */
84: } value; /* either number or string */
1.10 itojun 85: uint32_t mask; /* mask before comparison with value */
1.1 deraadt 86: char nospflag; /* supress space character */
87: char desc[MAXDESC]; /* description */
88: };
89:
1.8 millert 90: extern int apprentice(char *, int);
91: extern int ascmagic(unsigned char *, int);
92: extern void ckfputs(const char *, FILE *);
1.1 deraadt 93: struct stat;
1.8 millert 94: extern int fsmagic(const char *, struct stat *);
95: extern int is_compress(const unsigned char *, int *);
96: extern int is_tar(unsigned char *, int);
97: extern void mdump(struct magic *);
98: extern void process(const char *, int);
99: extern void showstr(FILE *, const char *, int);
100: extern int softmagic(unsigned char *, int);
101: extern int tryit(unsigned char *, int, int);
102: extern int zmagic(unsigned char *, int);
103: extern void ckfprintf(FILE *, const char *, ...);
1.10 itojun 104: extern uint32_t signextend(struct magic *, uint32_t);
1.8 millert 105: extern int internatmagic(unsigned char *, int);
1.11 ! ian 106: extern void tryelf(int, unsigned char *, int);
1.1 deraadt 107:
108:
109: extern int errno; /* Some unixes don't define this.. */
110:
111: extern char *progname; /* the program name */
112: extern char *magicfile; /* name of the magic file */
113: extern int lineno; /* current line number in magic file */
114:
115: extern struct magic *magic; /* array of magic entries */
116: extern int nmagic; /* number of valid magic[]s */
117:
118:
119: extern int debug; /* enable debugging? */
120: extern int zflag; /* process compressed files? */
121: extern int lflag; /* follow symbolic links? */
122:
123: extern int optind; /* From getopt(3) */
124: extern char *optarg;
125:
1.3 millert 126: #if defined(sun) || defined(__sun__) || defined (__sun)
127: # if defined(__svr4) || defined (__SVR4) || defined(__svr4__)
128: # define SOLARIS
129: # else
130: # define SUNOS
131: # endif
132: #endif
133:
134:
135: #if !defined(__STDC__) || defined(SUNOS) || defined(__convex__)
1.1 deraadt 136: extern int sys_nerr;
137: extern char *sys_errlist[];
138: #define strerror(e) \
139: (((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
140: #define strtoul(a, b, c) strtol(a, b, c)
141: #endif
142:
143: #ifndef MAXPATHLEN
144: #define MAXPATHLEN 512
145: #endif
1.3 millert 146:
147: #endif /* __file_h__ */