1284194Sdelphij/*
2284194Sdelphij * Copyright (c) Christos Zoulas 2003.
3284194Sdelphij * All Rights Reserved.
4284194Sdelphij *
5284194Sdelphij * Redistribution and use in source and binary forms, with or without
6284194Sdelphij * modification, are permitted provided that the following conditions
7284194Sdelphij * are met:
8284194Sdelphij * 1. Redistributions of source code must retain the above copyright
9284194Sdelphij *    notice immediately at the beginning of the file, without modification,
10284194Sdelphij *    this list of conditions, and the following disclaimer.
11284194Sdelphij * 2. Redistributions in binary form must reproduce the above copyright
12284194Sdelphij *    notice, this list of conditions and the following disclaimer in the
13284194Sdelphij *    documentation and/or other materials provided with the distribution.
14284194Sdelphij *
15284194Sdelphij * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16284194Sdelphij * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17284194Sdelphij * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18284194Sdelphij * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
19284194Sdelphij * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20284194Sdelphij * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21284194Sdelphij * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22284194Sdelphij * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23284194Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24284194Sdelphij * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25284194Sdelphij * SUCH DAMAGE.
26284194Sdelphij */
27284194Sdelphij#ifndef _MAGIC_H
28284194Sdelphij#define _MAGIC_H
29284194Sdelphij
30284194Sdelphij#include <sys/types.h>
31284194Sdelphij
32284194Sdelphij#define	MAGIC_NONE		0x000000 /* No flags */
33284194Sdelphij#define	MAGIC_DEBUG		0x000001 /* Turn on debugging */
34284194Sdelphij#define	MAGIC_SYMLINK		0x000002 /* Follow symlinks */
35284194Sdelphij#define	MAGIC_COMPRESS		0x000004 /* Check inside compressed files */
36284194Sdelphij#define	MAGIC_DEVICES		0x000008 /* Look at the contents of devices */
37284194Sdelphij#define	MAGIC_MIME_TYPE		0x000010 /* Return the MIME type */
38284194Sdelphij#define	MAGIC_CONTINUE		0x000020 /* Return all matches */
39284194Sdelphij#define	MAGIC_CHECK		0x000040 /* Print warnings to stderr */
40284194Sdelphij#define	MAGIC_PRESERVE_ATIME	0x000080 /* Restore access time on exit */
41284194Sdelphij#define	MAGIC_RAW		0x000100 /* Don't translate unprintable chars */
42284194Sdelphij#define	MAGIC_ERROR		0x000200 /* Handle ENOENT etc as real errors */
43284194Sdelphij#define	MAGIC_MIME_ENCODING	0x000400 /* Return the MIME encoding */
44284194Sdelphij#define MAGIC_MIME		(MAGIC_MIME_TYPE|MAGIC_MIME_ENCODING)
45284194Sdelphij#define	MAGIC_APPLE		0x000800 /* Return the Apple creator and type */
46284194Sdelphij
47284194Sdelphij#define	MAGIC_NO_CHECK_COMPRESS	0x001000 /* Don't check for compressed files */
48284194Sdelphij#define	MAGIC_NO_CHECK_TAR	0x002000 /* Don't check for tar files */
49284194Sdelphij#define	MAGIC_NO_CHECK_SOFT	0x004000 /* Don't check magic entries */
50284194Sdelphij#define	MAGIC_NO_CHECK_APPTYPE	0x008000 /* Don't check application type */
51284194Sdelphij#define	MAGIC_NO_CHECK_ELF	0x010000 /* Don't check for elf details */
52284194Sdelphij#define	MAGIC_NO_CHECK_TEXT	0x020000 /* Don't check for text files */
53284194Sdelphij#define	MAGIC_NO_CHECK_CDF	0x040000 /* Don't check for cdf files */
54284194Sdelphij#define	MAGIC_NO_CHECK_TOKENS	0x100000 /* Don't check tokens */
55284194Sdelphij#define MAGIC_NO_CHECK_ENCODING 0x200000 /* Don't check text encodings */
56284194Sdelphij
57284194Sdelphij/* No built-in tests; only consult the magic file */
58284194Sdelphij#define MAGIC_NO_CHECK_BUILTIN	( \
59284194Sdelphij	MAGIC_NO_CHECK_COMPRESS	| \
60284194Sdelphij	MAGIC_NO_CHECK_TAR	| \
61284194Sdelphij/*	MAGIC_NO_CHECK_SOFT	| */ \
62284194Sdelphij	MAGIC_NO_CHECK_APPTYPE	| \
63284194Sdelphij	MAGIC_NO_CHECK_ELF	| \
64284194Sdelphij	MAGIC_NO_CHECK_TEXT	| \
65284194Sdelphij	MAGIC_NO_CHECK_CDF	| \
66284194Sdelphij	MAGIC_NO_CHECK_TOKENS	| \
67284194Sdelphij	MAGIC_NO_CHECK_ENCODING	| \
68284194Sdelphij	0			  \
69284194Sdelphij)
70284194Sdelphij
71284194Sdelphij/* Defined for backwards compatibility (renamed) */
72284194Sdelphij#define	MAGIC_NO_CHECK_ASCII	MAGIC_NO_CHECK_TEXT
73284194Sdelphij
74284194Sdelphij/* Defined for backwards compatibility; do nothing */
75284194Sdelphij#define	MAGIC_NO_CHECK_FORTRAN	0x000000 /* Don't check ascii/fortran */
76284194Sdelphij#define	MAGIC_NO_CHECK_TROFF	0x000000 /* Don't check ascii/troff */
77284194Sdelphij
78284194Sdelphij#define MAGIC_VERSION		X.YY	/* This implementation */
79284194Sdelphij
80284194Sdelphij
81284194Sdelphij#ifdef __cplusplus
82284194Sdelphijextern "C" {
83284194Sdelphij#endif
84284194Sdelphij
85284194Sdelphijtypedef struct magic_set *magic_t;
86284194Sdelphijmagic_t magic_open(int);
87284194Sdelphijvoid magic_close(magic_t);
88284194Sdelphij
89284194Sdelphijconst char *magic_getpath(const char *, int);
90284194Sdelphijconst char *magic_file(magic_t, const char *);
91284194Sdelphijconst char *magic_descriptor(magic_t, int);
92284194Sdelphijconst char *magic_buffer(magic_t, const void *, size_t);
93284194Sdelphij
94284194Sdelphijconst char *magic_error(magic_t);
95284194Sdelphijint magic_setflags(magic_t, int);
96284194Sdelphij
97284194Sdelphijint magic_version(void);
98284194Sdelphijint magic_load(magic_t, const char *);
99284194Sdelphijint magic_load_buffers(magic_t, void **, size_t *, size_t);
100284194Sdelphij
101284194Sdelphijint magic_compile(magic_t, const char *);
102284194Sdelphijint magic_check(magic_t, const char *);
103284194Sdelphijint magic_list(magic_t, const char *);
104284194Sdelphijint magic_errno(magic_t);
105284194Sdelphij
106284194Sdelphij#define MAGIC_PARAM_INDIR_MAX		0
107284194Sdelphij#define MAGIC_PARAM_NAME_MAX		1
108284194Sdelphij#define MAGIC_PARAM_ELF_PHNUM_MAX	2
109284194Sdelphij#define MAGIC_PARAM_ELF_SHNUM_MAX	3
110284194Sdelphij#define MAGIC_PARAM_ELF_NOTES_MAX	4
111284194Sdelphij
112284194Sdelphijint magic_setparam(magic_t, int, const void *);
113284194Sdelphijint magic_getparam(magic_t, int, void *);
114284194Sdelphij
115284194Sdelphij#ifdef __cplusplus
116284194Sdelphij};
117284194Sdelphij#endif
118284194Sdelphij
119284194Sdelphij#endif /* _MAGIC_H */
120