2 .\" Copyright (c) Christos Zoulas 2003.
3 .\" All Rights Reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice immediately at the beginning of the file, without modification,
10 .\" this list of conditions, and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
19 .\" ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 .Nd Magic number recognition library.
46 .Fn magic_open "int flags"
48 .Fn magic_close "magic_t cookie"
50 .Fn magic_error "magic_t cookie"
52 .Fn magic_errno "magic_t cookie"
54 .Fn magic_file "magic_t cookie, const char *filename"
56 .Fn magic_buffer "magic_t cookie, const void *buffer, size_t length"
58 .Fn magic_setflags "magic_t cookie, int flags"
60 .Fn magic_check "magic_t cookie, const char *filename"
62 .Fn magic_compile "magic_t cookie, const char *filename"
64 .Fn magic_load "magic_t cookie, const char *filename"
67 operate on the magic database file
70 .Xr magic __FSECTION__ .
74 creates a magic cookie pointer and returns it. It returns NULL if
75 there was an error allocating the magic cookie. The
77 argument specifies how the other magic functions should behave:
78 .Bl -tag -width MAGIC_COMPRESS
82 Print debugging messages to stderr.
84 If the file queried is a symlink, follow it.
86 If the file is compressed, unpack it and look at the contents.
88 If the file is a block or character special device, then open the device
89 and try to look in its contents.
91 Return a mime string, instead of a textual description.
93 Return all matches, not just the first.
95 Check the magic database for consistency and print warnings to stderr.
96 .It Dv MAGIC_PRESERVE_ATIME
97 On systems that support
101 attempt to preserve the access time of files analyzed.
103 Don't translate unprintable characters to a \eooo octal representation.
105 Treat operating system errors while trying to open files and follow symlinks
106 as real errors, instead of printing them in the magic buffer.
107 .It Dv MAGIC_NO_CHECK_APPTYPE
110 application type (only on EMX).
111 .It Dv MAGIC_NO_CHECK_ASCII
112 Check for various types of ascii files.
113 .It Dv MAGIC_NO_CHECK_COMPRESS
114 Don't look for, or inside compressed files.
115 .It Dv MAGIC_NO_CHECK_ELF
116 Don't print elf details.
117 .It Dv MAGIC_NO_CHECK_FORTRAN
118 Don't look for fortran sequences inside ascii files.
119 .It Dv MAGIC_NO_CHECK_SOFT
120 Don't consult magic files.
121 .It Dv MAGIC_NO_CHECK_TAR
122 Don't examine tar files.
123 .It Dv MAGIC_NO_CHECK_TOKENS
124 Don't look for known tokens inside ascii files.
125 .It Dv MAGIC_NO_CHECK_TROFF
126 Don't look for troff sequences inside ascii files.
132 .Xr magic __FSECTION__
133 database and deallocates any resources used.
137 function returns a textual explanation of the last error, or NULL if there was
142 function returns the last operating system error number
144 that was encountered by a system call.
148 function returns a textual description of the contents of the
150 argument, or NULL if an error occurred.
153 is NULL, then stdin is used.
157 function returns a textual description of the contents of the
171 function can be used to check the validity of entries in the colon
172 separated database files passed in as
174 or NULL for the default database. It returns 0 on success and -1 on
179 function can be used to compile the the colon
180 separated list of database files passed in as
182 or NULL for the default database. It returns 0 on success and -1 on
183 failure. The compiled files created are named from the
185 of each file argument with ".mgc" appended to it.
189 function must be used to load the the colon
190 separated list of database files passed in as
192 or NULL for the default database file
193 before any magic queries can performed.
195 The default database file is named by the MAGIC environment variable. If
196 that variable is not set, the default database file name is __MAGIC__.
199 adds ".mime" and/or ".mgc" to the database filename as appropriate.
203 returns a magic cookie on success and NULL on failure setting errno to
204 an appropriate value. It will set errno to EINVAL if an unsupported
205 value for flags was given.
211 functions return 0 on success and -1 on failure.
216 functions return a string on success and NULL on failure. The
218 function returns a textual description of the errors of the above
219 functions, or NULL if there was no error.
222 returns -1 on systems that don't support
227 .Dv MAGIC_PRESERVE_ATIME
230 .Bl -tag -width __MAGIC__.mime.mgc -compact
231 .It Pa __MAGIC__.mime
232 The non-compiled default magic mime database.
233 .It Pa __MAGIC__.mime.mgc
234 The compiled default magic mime database.
236 The non-compiled default magic database.
238 The compiled default magic database.
241 .Xr file __CSECTION__ ,
242 .Xr magic __FSECTION__
244 Måns Rullgård Initial libmagic implementation,
246 Christos Zoulas API cleanup, error code and allocation handling.