magic.h.in revision 284193
1139823Simp/*
210965Swollman * Copyright (c) Christos Zoulas 2003.
31541Srgrimes * All Rights Reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice immediately at the beginning of the file, without modification,
101541Srgrimes *    this list of conditions, and the following disclaimer.
111541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
121541Srgrimes *    notice, this list of conditions and the following disclaimer in the
131541Srgrimes *    documentation and/or other materials provided with the distribution.
141541Srgrimes *
151541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
161541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
171541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
181541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
191541Srgrimes * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
201541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
211541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
221541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
231541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
241541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
251541Srgrimes * SUCH DAMAGE.
261541Srgrimes */
271541Srgrimes#ifndef _MAGIC_H
281541Srgrimes#define _MAGIC_H
2910965Swollman
301541Srgrimes#include <sys/types.h>
311541Srgrimes
32172467Ssilby#define	MAGIC_NONE		0x000000 /* No flags */
33172467Ssilby#define	MAGIC_DEBUG		0x000001 /* Turn on debugging */
34172467Ssilby#define	MAGIC_SYMLINK		0x000002 /* Follow symlinks */
35125680Sbms#define	MAGIC_COMPRESS		0x000004 /* Check inside compressed files */
3655679Sshin#define	MAGIC_DEVICES		0x000008 /* Look at the contents of devices */
3756041Sshin#define	MAGIC_MIME_TYPE		0x000010 /* Return the MIME type */
3829514Sjoerg#define	MAGIC_CONTINUE		0x000020 /* Return all matches */
3929514Sjoerg#define	MAGIC_CHECK		0x000040 /* Print warnings to stderr */
401541Srgrimes#define	MAGIC_PRESERVE_ATIME	0x000080 /* Restore access time on exit */
411541Srgrimes#define	MAGIC_RAW		0x000100 /* Don't translate unprintable chars */
4276166Smarkm#define	MAGIC_ERROR		0x000200 /* Handle ENOENT etc as real errors */
43216758Slstewart#define	MAGIC_MIME_ENCODING	0x000400 /* Return the MIME encoding */
4447547Sdg#define MAGIC_MIME		(MAGIC_MIME_TYPE|MAGIC_MIME_ENCODING)
4576166Smarkm#define	MAGIC_APPLE		0x000800 /* Return the Apple creator and type */
461541Srgrimes
4776166Smarkm#define	MAGIC_NO_CHECK_COMPRESS	0x001000 /* Don't check for compressed files */
481541Srgrimes#define	MAGIC_NO_CHECK_TAR	0x002000 /* Don't check for tar files */
49254889Smarkj#define	MAGIC_NO_CHECK_SOFT	0x004000 /* Don't check magic entries */
501541Srgrimes#define	MAGIC_NO_CHECK_APPTYPE	0x008000 /* Don't check application type */
511541Srgrimes#define	MAGIC_NO_CHECK_ELF	0x010000 /* Don't check for elf details */
5276166Smarkm#define	MAGIC_NO_CHECK_TEXT	0x020000 /* Don't check for text files */
531541Srgrimes#define	MAGIC_NO_CHECK_CDF	0x040000 /* Don't check for cdf files */
54185571Sbz#define	MAGIC_NO_CHECK_TOKENS	0x100000 /* Don't check tokens */
551541Srgrimes#define MAGIC_NO_CHECK_ENCODING 0x200000 /* Don't check text encodings */
56196019Srwatson
571541Srgrimes/* No built-in tests; only consult the magic file */
58215166Slstewart#define MAGIC_NO_CHECK_BUILTIN	( \
591541Srgrimes	MAGIC_NO_CHECK_COMPRESS	| \
60254889Smarkj	MAGIC_NO_CHECK_TAR	| \
611541Srgrimes/*	MAGIC_NO_CHECK_SOFT	| */ \
621541Srgrimes	MAGIC_NO_CHECK_APPTYPE	| \
631541Srgrimes	MAGIC_NO_CHECK_ELF	| \
6462587Sitojun	MAGIC_NO_CHECK_TEXT	| \
65152592Sandre	MAGIC_NO_CHECK_CDF	| \
6655679Sshin	MAGIC_NO_CHECK_TOKENS	| \
6755679Sshin	MAGIC_NO_CHECK_ENCODING	| \
6862587Sitojun	0			  \
6955679Sshin)
7055679Sshin
711541Srgrimes/* Defined for backwards compatibility (renamed) */
721541Srgrimes#define	MAGIC_NO_CHECK_ASCII	MAGIC_NO_CHECK_TEXT
731541Srgrimes
741541Srgrimes/* Defined for backwards compatibility; do nothing */
751541Srgrimes#define	MAGIC_NO_CHECK_FORTRAN	0x000000 /* Don't check ascii/fortran */
761541Srgrimes#define	MAGIC_NO_CHECK_TROFF	0x000000 /* Don't check ascii/troff */
772788Sdg
781541Srgrimes#define MAGIC_VERSION		X.YY	/* This implementation */
792788Sdg
80237263Snp
81237263Snp#ifdef __cplusplus
82237263Snpextern "C" {
831541Srgrimes#endif
84171167Sgnn
85105199Ssamtypedef struct magic_set *magic_t;
86171167Sgnnmagic_t magic_open(int);
87105199Ssamvoid magic_close(magic_t);
8858698Sjlemon
8958698Sjlemonconst char *magic_getpath(const char *, int);
90163606Srwatsonconst char *magic_file(magic_t, const char *);
91163606Srwatsonconst char *magic_descriptor(magic_t, int);
92207369Sbzconst char *magic_buffer(magic_t, const void *, size_t);
93274225Sglebius
94195699Srwatsonconst char *magic_error(magic_t);
95195699Srwatsonint magic_setflags(magic_t, int);
961541Srgrimes
97207369Sbzint magic_version(void);
98207369Sbzint magic_load(magic_t, const char *);
99274225Sglebiusint magic_load_buffers(magic_t, void **, size_t *, size_t);
100195699Srwatson
101195699Srwatsonint magic_compile(magic_t, const char *);
102162110Sandreint magic_check(magic_t, const char *);
103226448Sandreint magic_list(magic_t, const char *);
104226448Sandreint magic_errno(magic_t);
105274225Sglebius
106226448Sandre#define MAGIC_PARAM_INDIR_MAX		0
107226448Sandre#define MAGIC_PARAM_NAME_MAX		1
108207369Sbz#define MAGIC_PARAM_ELF_PHNUM_MAX	2
109207369Sbz#define MAGIC_PARAM_ELF_SHNUM_MAX	3
110274225Sglebius#define MAGIC_PARAM_ELF_NOTES_MAX	4
111195699Srwatson
112195699Srwatsonint magic_setparam(magic_t, int, const void *);
113166405Sandreint magic_getparam(magic_t, int, void *);
114207369Sbz
115207369Sbz#ifdef __cplusplus
116274225Sglebius};
117195699Srwatson#endif
118183550Szec
119166405Sandre#endif /* _MAGIC_H */
120225169Sbz