1 .\" $File: libmagic.man,v 1.38 2015/09/11 17:24:09 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
28 .Dd September 11, 2015
36 .Nm magic_descriptor ,
43 .Nm magic_load_buffers ,
47 .Nd Magic number recognition library
53 .Fn magic_open "int flags"
55 .Fn magic_close "magic_t cookie"
57 .Fn magic_error "magic_t cookie"
59 .Fn magic_errno "magic_t cookie"
61 .Fn magic_descriptor "magic_t cookie" "int fd"
63 .Fn magic_file "magic_t cookie" "const char *filename"
65 .Fn magic_buffer "magic_t cookie" "const void *buffer" "size_t length"
67 .Fn magic_setflags "magic_t cookie" "int flags"
69 .Fn magic_check "magic_t cookie" "const char *filename"
71 .Fn magic_compile "magic_t cookie" "const char *filename"
73 .Fn magic_list "magic_t cookie" "const char *filename"
75 .Fn magic_load "magic_t cookie" "const char *filename"
77 .Fn magic_load_buffers "magic_t cookie" "void **buffers" "size_t *sizes" "size_t nbuffers"
79 .Fn magic_getparam "magic_t cookie" "int param" "void *value"
81 .Fn magic_setparam "magic_t cookie" "int param" "const void *value"
83 .Fn magic_version "void"
86 operate on the magic database file
89 .Xr magic __FSECTION__ .
93 creates a magic cookie pointer and returns it.
96 if there was an error allocating the magic cookie.
99 argument specifies how the other magic functions should behave:
100 .Bl -tag -width MAGIC_COMPRESS
104 Print debugging messages to stderr.
106 If the file queried is a symlink, follow it.
107 .It Dv MAGIC_COMPRESS
108 If the file is compressed, unpack it and look at the contents.
110 If the file is a block or character special device, then open the device
111 and try to look in its contents.
112 .It Dv MAGIC_MIME_TYPE
113 Return a MIME type string, instead of a textual description.
114 .It Dv MAGIC_MIME_ENCODING
115 Return a MIME encoding, instead of a textual description.
117 A shorthand for MAGIC_MIME_TYPE | MAGIC_MIME_ENCODING.
118 .It Dv MAGIC_CONTINUE
119 Return all matches, not just the first.
121 Check the magic database for consistency and print warnings to stderr.
122 .It Dv MAGIC_PRESERVE_ATIME
123 On systems that support
127 attempt to preserve the access time of files analysed.
129 Don't translate unprintable characters to a \eooo octal representation.
131 Treat operating system errors while trying to open files and follow symlinks
132 as real errors, instead of printing them in the magic buffer.
134 Return the Apple creator and type.
135 .It Dv MAGIC_EXTENSION
136 Return a slash-separated list of extensions for this file type.
137 .It Dv MAGIC_COMPRESS_TRANSP
138 Don't report on compression, only report about the uncompressed data.
139 .It Dv MAGIC_NO_CHECK_APPTYPE
142 application type (only on EMX).
143 .It Dv MAGIC_NO_CHECK_CDF
144 Don't get extra information on MS Composite Document Files.
145 .It Dv MAGIC_NO_CHECK_COMPRESS
146 Don't look inside compressed files.
147 .It Dv MAGIC_NO_CHECK_ELF
148 Don't print ELF details.
149 .It Dv MAGIC_NO_CHECK_ENCODING
150 Don't check text encodings.
151 .It Dv MAGIC_NO_CHECK_SOFT
152 Don't consult magic files.
153 .It Dv MAGIC_NO_CHECK_TAR
154 Don't examine tar files.
155 .It Dv MAGIC_NO_CHECK_TEXT
156 Don't check for various types of text files.
157 .It Dv MAGIC_NO_CHECK_TOKENS
158 Don't look for known tokens inside ascii files.
164 .Xr magic __FSECTION__
165 database and deallocates any resources used.
169 function returns a textual explanation of the last error, or
171 if there was no error.
175 function returns the last operating system error number
177 that was encountered by a system call.
181 function returns a textual description of the contents of the
185 if an error occurred.
194 function returns a textual description of the contents of the
198 if an error occurred.
202 function returns a textual description of the contents of the
213 Note that using both MIME flags together can also
214 return extra information on the charset.
218 function can be used to check the validity of entries in the colon
219 separated database files passed in as
223 for the default database.
224 It returns 0 on success and \-1 on failure.
228 function can be used to compile the the colon
229 separated list of database files passed in as
233 for the default database.
234 It returns 0 on success and \-1 on failure.
235 The compiled files created are named from the
237 of each file argument with
243 function dumps all magic entries in a human readable format,
244 dumping first the entries that are matched against binary files and then the
245 ones that match text files.
246 It takes and optional
248 argument which is a colon separated list of database files, or
250 for the default database.
254 function must be used to load the the colon
255 separated list of database files passed in as
259 for the default database file before any magic queries can performed.
261 The default database file is named by the MAGIC environment variable.
262 If that variable is not set, the default database file name is __MAGIC__.
266 to the database filename as appropriate.
269 .Fn magic_load_buffers
270 function takes an array of size
274 with a respective size for each in the array of
276 loaded with the contents of the magic databases from the filesystem.
277 This function can be used in environment where the magic library does
278 not have direct access to the filesystem, but can access the magic
279 database via shared memory or other IPC means.
285 allow getting and setting various limits related to the the magic
287 .Bl -column "MAGIC_PARAM_ELF_PHNUM_MAX" "size_t" "Default" -offset indent
288 .It Sy "Parameter" Ta Sy "Type" Ta Sy "Default"
289 .It Li MAGIC_PARAM_INDIR_MAX Ta size_t Ta 15
290 .It Li MAGIC_PARAM_NAME_MAX Ta size_t Ta 30
291 .It Li MAGIC_PARAM_ELF_NOTES_MAX Ta size_t Ta 256
292 .It Li MAGIC_PARAM_ELF_PHNUM_MAX Ta size_t Ta 128
293 .It Li MAGIC_PARAM_ELF_SHNUM_MAX Ta size_t Ta 32768
294 .It Li MAGIC_PARAM_REGEX_MAX Ta size_t Ta 8192
298 .Dv MAGIC_PARAM_INDIR_RECURSION
299 parameter controls how many levels of recursion will be followed for
300 indirect magic entries.
303 .Dv MAGIC_PARAM_NAME_RECURSION
304 parameter controls how many levels of recursion will be followed for
308 .Dv MAGIC_PARAM_NAME_MAX
309 parameter controls the maximum number of calls for name/use.
312 .Dv MAGIC_PARAM_NOTES_MAX
313 parameter controls how many ELF notes will be processed.
316 .Dv MAGIC_PARAM_PHNUM_MAX
317 parameter controls how many ELF program sections will be processed.
320 .Dv MAGIC_PARAM_SHNUM_MAX
321 parameter controls how many ELF sections will be processed.
325 command returns the version number of this library which is compiled into
326 the shared library using the constant
330 This can be used by client programs to verify that the version they compile
331 against is the same as the version that they run against.
335 returns a magic cookie on success and
337 on failure setting errno to an appropriate value.
340 if an unsupported value for flags was given.
347 functions return 0 on success and \-1 on failure.
353 functions return a string on success and
358 function returns a textual description of the errors of the above
361 if there was no error.
364 always returns the version number of the library.
367 returns \-1 on systems that don't support
372 .Dv MAGIC_PRESERVE_ATIME
375 .Bl -tag -width __MAGIC__.mgc -compact
377 The non-compiled default magic database.
379 The compiled default magic database.
382 .Xr file __CSECTION__ ,
383 .Xr magic __FSECTION__
385 .An M\(oans Rullg\(oard
386 Initial libmagic implementation, and configuration.
388 API cleanup, error code and allocation handling.