1 .\" $File: libmagic.man,v 1.45 2019/06/08 22:16:24 christos Exp $
3 .\" Copyright (c) Christos Zoulas 2003, 2018.
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 .Nm magic_load_buffers ,
48 .Nd Magic number recognition library
54 .Fn magic_open "int flags"
56 .Fn magic_close "magic_t cookie"
58 .Fn magic_error "magic_t cookie"
60 .Fn magic_errno "magic_t cookie"
62 .Fn magic_descriptor "magic_t cookie" "int fd"
64 .Fn magic_file "magic_t cookie" "const char *filename"
66 .Fn magic_buffer "magic_t cookie" "const void *buffer" "size_t length"
68 .Fn magic_getflags "magic_t cookie"
70 .Fn magic_setflags "magic_t cookie" "int flags"
72 .Fn magic_check "magic_t cookie" "const char *filename"
74 .Fn magic_compile "magic_t cookie" "const char *filename"
76 .Fn magic_list "magic_t cookie" "const char *filename"
78 .Fn magic_load "magic_t cookie" "const char *filename"
80 .Fn magic_load_buffers "magic_t cookie" "void **buffers" "size_t *sizes" "size_t nbuffers"
82 .Fn magic_getparam "magic_t cookie" "int param" "void *value"
84 .Fn magic_setparam "magic_t cookie" "int param" "const void *value"
86 .Fn magic_version "void"
89 operate on the magic database file
92 .Xr magic __FSECTION__ .
96 creates a magic cookie pointer and returns it.
99 if there was an error allocating the magic cookie.
102 argument specifies how the other magic functions should behave:
103 .Bl -tag -width MAGIC_COMPRESS
107 Print debugging messages to stderr.
109 If the file queried is a symlink, follow it.
110 .It Dv MAGIC_COMPRESS
111 If the file is compressed, unpack it and look at the contents.
113 If the file is a block or character special device, then open the device
114 and try to look in its contents.
115 .It Dv MAGIC_MIME_TYPE
116 Return a MIME type string, instead of a textual description.
117 .It Dv MAGIC_MIME_ENCODING
118 Return a MIME encoding, instead of a textual description.
120 A shorthand for MAGIC_MIME_TYPE | MAGIC_MIME_ENCODING.
121 .It Dv MAGIC_CONTINUE
122 Return all matches, not just the first.
124 Check the magic database for consistency and print warnings to stderr.
125 .It Dv MAGIC_PRESERVE_ATIME
126 On systems that support
130 attempt to preserve the access time of files analysed.
132 Don't translate unprintable characters to a \eooo octal representation.
134 Treat operating system errors while trying to open files and follow symlinks
135 as real errors, instead of printing them in the magic buffer.
137 Return the Apple creator and type.
138 .It Dv MAGIC_EXTENSION
139 Return a slash-separated list of extensions for this file type.
140 .It Dv MAGIC_COMPRESS_TRANSP
141 Don't report on compression, only report about the uncompressed data.
142 .It Dv MAGIC_NO_CHECK_APPTYPE
145 application type (only on EMX).
146 .It Dv MAGIC_NO_CHECK_CDF
147 Don't get extra information on MS Composite Document Files.
148 .It Dv MAGIC_NO_CHECK_COMPRESS
149 Don't look inside compressed files.
150 .It Dv MAGIC_NO_CHECK_ELF
151 Don't print ELF details.
152 .It Dv MAGIC_NO_CHECK_ENCODING
153 Don't check text encodings.
154 .It Dv MAGIC_NO_CHECK_SOFT
155 Don't consult magic files.
156 .It Dv MAGIC_NO_CHECK_TAR
157 Don't examine tar files.
158 .It Dv MAGIC_NO_CHECK_TEXT
159 Don't check for various types of text files.
160 .It Dv MAGIC_NO_CHECK_TOKENS
161 Don't look for known tokens inside ascii files.
162 .It Dv MAGIC_NO_CHECK_JSON
163 Don't examine JSON files.
164 .It Dv MAGIC_NO_CHECK_CSV
165 Don't examine CSV files.
171 .Xr magic __FSECTION__
172 database and deallocates any resources used.
176 function returns a textual explanation of the last error, or
178 if there was no error.
182 function returns the last operating system error number
184 that was encountered by a system call.
188 function returns a textual description of the contents of the
192 if an error occurred.
201 function returns a textual description of the contents of the
205 if an error occurred.
209 function returns a textual description of the contents of the
217 functions returns a value representing current
226 Note that using both MIME flags together can also
227 return extra information on the charset.
231 function can be used to check the validity of entries in the colon
232 separated database files passed in as
236 for the default database.
237 It returns 0 on success and \-1 on failure.
241 function can be used to compile the colon
242 separated list of database files passed in as
246 for the default database.
247 It returns 0 on success and \-1 on failure.
248 The compiled files created are named from the
250 of each file argument with
256 function dumps all magic entries in a human readable format,
257 dumping first the entries that are matched against binary files and then the
258 ones that match text files.
259 It takes and optional
261 argument which is a colon separated list of database files, or
263 for the default database.
267 function must be used to load the colon
268 separated list of database files passed in as
272 for the default database file before any magic queries can performed.
274 The default database file is named by the MAGIC environment variable.
275 If that variable is not set, the default database file name is __MAGIC__.
279 to the database filename as appropriate.
282 .Fn magic_load_buffers
283 function takes an array of size
287 with a respective size for each in the array of
289 loaded with the contents of the magic databases from the filesystem.
290 This function can be used in environment where the magic library does
291 not have direct access to the filesystem, but can access the magic
292 database via shared memory or other IPC means.
298 allow getting and setting various limits related to the magic
300 .Bl -column "MAGIC_PARAM_ELF_PHNUM_MAX" "size_t" "Default" -offset indent
301 .It Sy "Parameter" Ta Sy "Type" Ta Sy "Default"
302 .It Li MAGIC_PARAM_INDIR_MAX Ta size_t Ta 15
303 .It Li MAGIC_PARAM_NAME_MAX Ta size_t Ta 30
304 .It Li MAGIC_PARAM_ELF_NOTES_MAX Ta size_t Ta 256
305 .It Li MAGIC_PARAM_ELF_PHNUM_MAX Ta size_t Ta 128
306 .It Li MAGIC_PARAM_ELF_SHNUM_MAX Ta size_t Ta 32768
307 .It Li MAGIC_PARAM_REGEX_MAX Ta size_t Ta 8192
308 .It Li MAGIC_PARAM_BYTES_MAX Ta size_t Ta 1048576
312 .Dv MAGIC_PARAM_INDIR_RECURSION
313 parameter controls how many levels of recursion will be followed for
314 indirect magic entries.
317 .Dv MAGIC_PARAM_NAME_RECURSION
318 parameter controls how many levels of recursion will be followed for
322 .Dv MAGIC_PARAM_NAME_MAX
323 parameter controls the maximum number of calls for name/use.
326 .Dv MAGIC_PARAM_NOTES_MAX
327 parameter controls how many ELF notes will be processed.
330 .Dv MAGIC_PARAM_PHNUM_MAX
331 parameter controls how many ELF program sections will be processed.
334 .Dv MAGIC_PARAM_SHNUM_MAX
335 parameter controls how many ELF sections will be processed.
339 command returns the version number of this library which is compiled into
340 the shared library using the constant
344 This can be used by client programs to verify that the version they compile
345 against is the same as the version that they run against.
349 returns a magic cookie on success and
351 on failure setting errno to an appropriate value.
354 if an unsupported value for flags was given.
361 functions return 0 on success and \-1 on failure.
367 functions return a string on success and
372 function returns a textual description of the errors of the above
375 if there was no error.
378 always returns the version number of the library.
381 returns \-1 on systems that don't support
386 .Dv MAGIC_PRESERVE_ATIME
389 .Bl -tag -width __MAGIC__.mgc -compact
391 The non-compiled default magic database.
393 The compiled default magic database.
396 .Xr file __CSECTION__ ,
397 .Xr magic __FSECTION__
403 where the buffer and the file contain the same data
404 can produce different results, because in the
406 case, the program can
412 .An M\(oans Rullg\(oard
413 Initial libmagic implementation, and configuration.
415 API cleanup, error code and allocation handling.