1267843Sdelphij/*
2267843Sdelphij * Copyright (c) Christos Zoulas 2003.
3267843Sdelphij * All Rights Reserved.
4267843Sdelphij *
5267843Sdelphij * Redistribution and use in source and binary forms, with or without
6267843Sdelphij * modification, are permitted provided that the following conditions
7267843Sdelphij * are met:
8267843Sdelphij * 1. Redistributions of source code must retain the above copyright
9267843Sdelphij *    notice immediately at the beginning of the file, without modification,
10267843Sdelphij *    this list of conditions, and the following disclaimer.
11267843Sdelphij * 2. Redistributions in binary form must reproduce the above copyright
12267843Sdelphij *    notice, this list of conditions and the following disclaimer in the
13267843Sdelphij *    documentation and/or other materials provided with the distribution.
14267843Sdelphij *
15267843Sdelphij * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16267843Sdelphij * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17267843Sdelphij * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18267843Sdelphij * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
19267843Sdelphij * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20267843Sdelphij * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21267843Sdelphij * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22267843Sdelphij * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23267843Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24267843Sdelphij * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25267843Sdelphij * SUCH DAMAGE.
26267843Sdelphij */
27267843Sdelphij#ifndef _MAGIC_H
28267843Sdelphij#define _MAGIC_H
29267843Sdelphij
30267843Sdelphij#include <sys/types.h>
31267843Sdelphij
32284237Sdelphij#define	MAGIC_NONE		0x0000000 /* No flags */
33284237Sdelphij#define	MAGIC_DEBUG		0x0000001 /* Turn on debugging */
34284237Sdelphij#define	MAGIC_SYMLINK		0x0000002 /* Follow symlinks */
35284237Sdelphij#define	MAGIC_COMPRESS		0x0000004 /* Check inside compressed files */
36284237Sdelphij#define	MAGIC_DEVICES		0x0000008 /* Look at the contents of devices */
37284237Sdelphij#define	MAGIC_MIME_TYPE		0x0000010 /* Return the MIME type */
38284237Sdelphij#define	MAGIC_CONTINUE		0x0000020 /* Return all matches */
39284237Sdelphij#define	MAGIC_CHECK		0x0000040 /* Print warnings to stderr */
40284237Sdelphij#define	MAGIC_PRESERVE_ATIME	0x0000080 /* Restore access time on exit */
41284237Sdelphij#define	MAGIC_RAW		0x0000100 /* Don't convert unprintable chars */
42284237Sdelphij#define	MAGIC_ERROR		0x0000200 /* Handle ENOENT etc as real errors */
43284237Sdelphij#define	MAGIC_MIME_ENCODING	0x0000400 /* Return the MIME encoding */
44267843Sdelphij#define MAGIC_MIME		(MAGIC_MIME_TYPE|MAGIC_MIME_ENCODING)
45284237Sdelphij#define	MAGIC_APPLE		0x0000800 /* Return the Apple creator/type */
46284237Sdelphij#define	MAGIC_EXTENSION		0x1000000 /* Return a /-separated list of
47284237Sdelphij					   * extensions */
48284237Sdelphij#define MAGIC_COMPRESS_TRANSP	0x2000000 /* Check inside compressed files
49284237Sdelphij					   * but not report compression */
50284237Sdelphij#define MAGIC_NODESC		(MAGIC_EXTENSION|MAGIC_MIME|MAGIC_APPLE)
51267843Sdelphij
52284237Sdelphij#define	MAGIC_NO_CHECK_COMPRESS	0x0001000 /* Don't check for compressed files */
53284237Sdelphij#define	MAGIC_NO_CHECK_TAR	0x0002000 /* Don't check for tar files */
54284237Sdelphij#define	MAGIC_NO_CHECK_SOFT	0x0004000 /* Don't check magic entries */
55284237Sdelphij#define	MAGIC_NO_CHECK_APPTYPE	0x0008000 /* Don't check application type */
56284237Sdelphij#define	MAGIC_NO_CHECK_ELF	0x0010000 /* Don't check for elf details */
57284237Sdelphij#define	MAGIC_NO_CHECK_TEXT	0x0020000 /* Don't check for text files */
58284237Sdelphij#define	MAGIC_NO_CHECK_CDF	0x0040000 /* Don't check for cdf files */
59360521Sdelphij#define MAGIC_NO_CHECK_CSV	0x0080000 /* Don't check for CSV files */
60284237Sdelphij#define	MAGIC_NO_CHECK_TOKENS	0x0100000 /* Don't check tokens */
61284237Sdelphij#define MAGIC_NO_CHECK_ENCODING 0x0200000 /* Don't check text encodings */
62354939Sdelphij#define MAGIC_NO_CHECK_JSON	0x0400000 /* Don't check for JSON files */
63267843Sdelphij
64267843Sdelphij/* No built-in tests; only consult the magic file */
65267843Sdelphij#define MAGIC_NO_CHECK_BUILTIN	( \
66267843Sdelphij	MAGIC_NO_CHECK_COMPRESS	| \
67267843Sdelphij	MAGIC_NO_CHECK_TAR	| \
68267843Sdelphij/*	MAGIC_NO_CHECK_SOFT	| */ \
69267843Sdelphij	MAGIC_NO_CHECK_APPTYPE	| \
70267843Sdelphij	MAGIC_NO_CHECK_ELF	| \
71267843Sdelphij	MAGIC_NO_CHECK_TEXT	| \
72360521Sdelphij	MAGIC_NO_CHECK_CSV	| \
73267843Sdelphij	MAGIC_NO_CHECK_CDF	| \
74267843Sdelphij	MAGIC_NO_CHECK_TOKENS	| \
75267843Sdelphij	MAGIC_NO_CHECK_ENCODING	| \
76354939Sdelphij	MAGIC_NO_CHECK_JSON	| \
77267843Sdelphij	0			  \
78267843Sdelphij)
79267843Sdelphij
80328874Seadler#define MAGIC_SNPRINTB "\177\020\
81328874Seadlerb\0debug\0\
82328874Seadlerb\1symlink\0\
83328874Seadlerb\2compress\0\
84328874Seadlerb\3devices\0\
85328874Seadlerb\4mime_type\0\
86328874Seadlerb\5continue\0\
87328874Seadlerb\6check\0\
88328874Seadlerb\7preserve_atime\0\
89328874Seadlerb\10raw\0\
90328874Seadlerb\11error\0\
91328874Seadlerb\12mime_encoding\0\
92328874Seadlerb\13apple\0\
93328874Seadlerb\14no_check_compress\0\
94328874Seadlerb\15no_check_tar\0\
95328874Seadlerb\16no_check_soft\0\
96328874Seadlerb\17no_check_sapptype\0\
97328874Seadlerb\20no_check_elf\0\
98328874Seadlerb\21no_check_text\0\
99328874Seadlerb\22no_check_cdf\0\
100328874Seadlerb\23no_check_reserved0\0\
101328874Seadlerb\24no_check_tokens\0\
102328874Seadlerb\25no_check_encoding\0\
103354939Sdelphijb\26no_check_json\0\
104328874Seadlerb\27no_check_reserved2\0\
105328874Seadlerb\30extension\0\
106328874Seadlerb\31transp_compression\0\
107328874Seadler"
108328874Seadler
109267843Sdelphij/* Defined for backwards compatibility (renamed) */
110267843Sdelphij#define	MAGIC_NO_CHECK_ASCII	MAGIC_NO_CHECK_TEXT
111267843Sdelphij
112267843Sdelphij/* Defined for backwards compatibility; do nothing */
113267843Sdelphij#define	MAGIC_NO_CHECK_FORTRAN	0x000000 /* Don't check ascii/fortran */
114267843Sdelphij#define	MAGIC_NO_CHECK_TROFF	0x000000 /* Don't check ascii/troff */
115267843Sdelphij
116267843Sdelphij#define MAGIC_VERSION		X.YY	/* This implementation */
117267843Sdelphij
118267843Sdelphij
119267843Sdelphij#ifdef __cplusplus
120267843Sdelphijextern "C" {
121267843Sdelphij#endif
122267843Sdelphij
123267843Sdelphijtypedef struct magic_set *magic_t;
124267843Sdelphijmagic_t magic_open(int);
125267843Sdelphijvoid magic_close(magic_t);
126267843Sdelphij
127267843Sdelphijconst char *magic_getpath(const char *, int);
128267843Sdelphijconst char *magic_file(magic_t, const char *);
129267843Sdelphijconst char *magic_descriptor(magic_t, int);
130267843Sdelphijconst char *magic_buffer(magic_t, const void *, size_t);
131267843Sdelphij
132267843Sdelphijconst char *magic_error(magic_t);
133328874Seadlerint magic_getflags(magic_t);
134267843Sdelphijint magic_setflags(magic_t, int);
135267843Sdelphij
136267843Sdelphijint magic_version(void);
137267843Sdelphijint magic_load(magic_t, const char *);
138275698Sdelphijint magic_load_buffers(magic_t, void **, size_t *, size_t);
139275698Sdelphij
140267843Sdelphijint magic_compile(magic_t, const char *);
141267843Sdelphijint magic_check(magic_t, const char *);
142267843Sdelphijint magic_list(magic_t, const char *);
143267843Sdelphijint magic_errno(magic_t);
144267843Sdelphij
145275698Sdelphij#define MAGIC_PARAM_INDIR_MAX		0
146275698Sdelphij#define MAGIC_PARAM_NAME_MAX		1
147275698Sdelphij#define MAGIC_PARAM_ELF_PHNUM_MAX	2
148275698Sdelphij#define MAGIC_PARAM_ELF_SHNUM_MAX	3
149276577Sdelphij#define MAGIC_PARAM_ELF_NOTES_MAX	4
150288143Sdelphij#define MAGIC_PARAM_REGEX_MAX		5
151299736Sdelphij#define	MAGIC_PARAM_BYTES_MAX		6
152275698Sdelphij
153275698Sdelphijint magic_setparam(magic_t, int, const void *);
154275698Sdelphijint magic_getparam(magic_t, int, void *);
155275698Sdelphij
156267843Sdelphij#ifdef __cplusplus
157267843Sdelphij};
158267843Sdelphij#endif
159267843Sdelphij
160267843Sdelphij#endif /* _MAGIC_H */
161