1 .\" $File: libmagic.man,v 1.28 2014/03/02 14:47:16 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
36 .Nm magic_descriptor ,
44 .Nd Magic number recognition library
50 .Fn magic_open "int flags"
52 .Fn magic_close "magic_t cookie"
54 .Fn magic_error "magic_t cookie"
56 .Fn magic_errno "magic_t cookie"
58 .Fn magic_descriptor "magic_t cookie" "int fd"
60 .Fn magic_file "magic_t cookie" "const char *filename"
62 .Fn magic_buffer "magic_t cookie" "const void *buffer" "size_t length"
64 .Fn magic_setflags "magic_t cookie" "int flags"
66 .Fn magic_check "magic_t cookie" "const char *filename"
68 .Fn magic_compile "magic_t cookie" "const char *filename"
70 .Fn magic_list "magic_t cookie" "const char *filename"
72 .Fn magic_load "magic_t cookie" "const char *filename"
74 .Fn magic_version "void"
77 operate on the magic database file
80 .Xr magic __FSECTION__ .
84 creates a magic cookie pointer and returns it.
87 if there was an error allocating the magic cookie.
90 argument specifies how the other magic functions should behave:
91 .Bl -tag -width MAGIC_COMPRESS
95 Print debugging messages to stderr.
97 If the file queried is a symlink, follow it.
99 If the file is compressed, unpack it and look at the contents.
101 If the file is a block or character special device, then open the device
102 and try to look in its contents.
103 .It Dv MAGIC_MIME_TYPE
104 Return a MIME type string, instead of a textual description.
105 .It Dv MAGIC_MIME_ENCODING
106 Return a MIME encoding, instead of a textual description.
108 A shorthand for MAGIC_MIME_TYPE | MAGIC_MIME_ENCODING.
109 .It Dv MAGIC_CONTINUE
110 Return all matches, not just the first.
112 Check the magic database for consistency and print warnings to stderr.
113 .It Dv MAGIC_PRESERVE_ATIME
114 On systems that support
118 attempt to preserve the access time of files analysed.
120 Don't translate unprintable characters to a \eooo octal representation.
122 Treat operating system errors while trying to open files and follow symlinks
123 as real errors, instead of printing them in the magic buffer.
125 Return the Apple creator and type.
126 .It Dv MAGIC_NO_CHECK_APPTYPE
129 application type (only on EMX).
130 .It Dv MAGIC_NO_CHECK_CDF
131 Don't get extra information on MS Composite Document Files.
132 .It Dv MAGIC_NO_CHECK_COMPRESS
133 Don't look inside compressed files.
134 .It Dv MAGIC_NO_CHECK_ELF
135 Don't print ELF details.
136 .It Dv MAGIC_NO_CHECK_ENCODING
137 Don't check text encodings.
138 .It Dv MAGIC_NO_CHECK_SOFT
139 Don't consult magic files.
140 .It Dv MAGIC_NO_CHECK_TAR
141 Don't examine tar files.
142 .It Dv MAGIC_NO_CHECK_TEXT
143 Don't check for various types of text files.
144 .It Dv MAGIC_NO_CHECK_TOKENS
145 Don't look for known tokens inside ascii files.
151 .Xr magic __FSECTION__
152 database and deallocates any resources used.
156 function returns a textual explanation of the last error, or
158 if there was no error.
162 function returns the last operating system error number
164 that was encountered by a system call.
168 function returns a textual description of the contents of the
172 if an error occurred.
181 function returns a textual description of the contents of the
185 if an error occurred.
189 function returns a textual description of the contents of the
200 Note that using both MIME flags together can also
201 return extra information on the charset.
205 function can be used to check the validity of entries in the colon
206 separated database files passed in as
210 for the default database.
211 It returns 0 on success and \-1 on failure.
215 function can be used to compile the the colon
216 separated list of database files passed in as
220 for the default database.
221 It returns 0 on success and \-1 on failure.
222 The compiled files created are named from the
224 of each file argument with
230 function dumps all magic entries in a human readable format,
231 dumping first the entries that are matched against binary files and then the
232 ones that match text files.
233 It takes and optional
235 argument which is a colon separated list of database files, or
237 for the default database.
241 function must be used to load the the colon
242 separated list of database files passed in as
246 for the default database file before any magic queries can performed.
248 The default database file is named by the MAGIC environment variable.
249 If that variable is not set, the default database file name is __MAGIC__.
253 to the database filename as appropriate.
257 command returns the version number of this library which is compiled into
258 the shared library using the constant
262 This can be used by client programs to verify that the version they compile
263 against is the same as the version that they run against.
267 returns a magic cookie on success and
269 on failure setting errno to an appropriate value.
272 if an unsupported value for flags was given.
279 functions return 0 on success and \-1 on failure.
285 functions return a string on success and
290 function returns a textual description of the errors of the above
293 if there was no error.
296 always returns the version number of the library.
299 returns \-1 on systems that don't support
304 .Dv MAGIC_PRESERVE_ATIME
307 .Bl -tag -width __MAGIC__.mgc -compact
309 The non-compiled default magic database.
311 The compiled default magic database.
314 .Xr file __CSECTION__ ,
315 .Xr magic __FSECTION__
317 .An M\(oans Rullg\(oard
318 Initial libmagic implementation, and configuration.
320 API cleanup, error code and allocation handling.