1 .\" $File: libmagic.man,v 1.24 2011/05/13 22:11:44 christos Exp $
3 .\" Copyright (c) Christos Zoulas 2003.
4 .\" All Rights Reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice immediately at the beginning of the file, without modification,
11 .\" this list of conditions, and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
16 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 .\" ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .Nm magic_descriptor ,
41 .Nd Magic number recognition library
47 .Fn magic_open "int flags"
49 .Fn magic_close "magic_t cookie"
51 .Fn magic_error "magic_t cookie"
53 .Fn magic_errno "magic_t cookie"
55 .Fn magic_descriptor "magic_t cookie, "int fd"
57 .Fn magic_file "magic_t cookie, const char *filename"
59 .Fn magic_buffer "magic_t cookie" "const void *buffer" "size_t length"
61 .Fn magic_setflags "magic_t cookie" "int flags"
63 .Fn magic_check "magic_t cookie" "const char *filename"
65 .Fn magic_compile "magic_t cookie" "const char *filename"
67 .Fn magic_load "magic_t cookie" "const char *filename"
70 operate on the magic database file
73 .Xr magic __FSECTION__ .
77 creates a magic cookie pointer and returns it.
80 if there was an error allocating the magic cookie.
83 argument specifies how the other magic functions should behave:
84 .Bl -tag -width MAGIC_COMPRESS
88 Print debugging messages to stderr.
90 If the file queried is a symlink, follow it.
92 If the file is compressed, unpack it and look at the contents.
94 If the file is a block or character special device, then open the device
95 and try to look in its contents.
96 .It Dv MAGIC_MIME_TYPE
97 Return a MIME type string, instead of a textual description.
98 .It Dv MAGIC_MIME_ENCODING
99 Return a MIME encoding, instead of a textual description.
101 A shorthand for MAGIC_MIME_TYPE | MAGIC_MIME_ENCODING.
102 .It Dv MAGIC_CONTINUE
103 Return all matches, not just the first.
105 Check the magic database for consistency and print warnings to stderr.
106 .It Dv MAGIC_PRESERVE_ATIME
107 On systems that support
111 attempt to preserve the access time of files analysed.
113 Don't translate unprintable characters to a \eooo octal representation.
115 Treat operating system errors while trying to open files and follow symlinks
116 as real errors, instead of printing them in the magic buffer.
118 Return the Apple creator and type.
119 .It Dv MAGIC_NO_CHECK_APPTYPE
122 application type (only on EMX).
123 .It Dv MAGIC_NO_CHECK_CDF
124 Don't get extra information on MS Composite Document Files.
125 .It Dv MAGIC_NO_CHECK_COMPRESS
126 Don't look inside compressed files.
127 .It Dv MAGIC_NO_CHECK_ELF
128 Don't print ELF details.
129 .It Dv NO_CHECK_ENCODING
130 Don't check text encodings.
131 .It Dv MAGIC_NO_CHECK_SOFT
132 Don't consult magic files.
133 .It Dv MAGIC_NO_CHECK_TAR
134 Don't examine tar files.
135 .It Dv MAGIC_NO_CHECK_TEXT
136 Don't check for various types of text files.
137 .It Dv MAGIC_NO_CHECK_TOKENS
138 Don't look for known tokens inside ascii files.
144 .Xr magic __FSECTION__
145 database and deallocates any resources used.
149 function returns a textual explanation of the last error, or
151 if there was no error.
155 function returns the last operating system error number
157 that was encountered by a system call.
161 function returns a textual description of the contents of the
165 if an error occurred.
174 function returns a textual description of the contents of the
178 if an error occurred.
182 function returns a textual description of the contents of the
193 Note that using both MIME flags together can also
194 return extra information on the charset.
198 function can be used to check the validity of entries in the colon
199 separated database files passed in as
203 for the default database.
204 It returns 0 on success and \-1 on failure.
208 function can be used to compile the the colon
209 separated list of database files passed in as
213 for the default database.
214 It returns 0 on success and \-1 on failure.
215 The compiled files created are named from the
217 of each file argument with
223 function must be used to load the the colon
224 separated list of database files passed in as
228 for the default database file before any magic queries can performed.
230 The default database file is named by the MAGIC environment variable.
231 If that variable is not set, the default database file name is __MAGIC__.
235 to the database filename as appropriate.
239 returns a magic cookie on success and
241 on failure setting errno to an appropriate value.
244 if an unsupported value for flags was given.
250 functions return 0 on success and \-1 on failure.
255 functions return a string on success and
260 function returns a textual description of the errors of the above
263 if there was no error.
266 returns \-1 on systems that don't support
271 .Dv MAGIC_PRESERVE_ATIME
274 .Bl -tag -width __MAGIC__.mgc -compact
276 The non-compiled default magic database.
278 The compiled default magic database.
281 .Xr file __CSECTION__ ,
282 .Xr magic __FSECTION__
284 .An M\(oans Rullg\(oard
285 Initial libmagic implementation, and configuration.
287 API cleanup, error code and allocation handling.