1 .\" $File: libmagic.man,v 1.19 2008/10/06 20:16:04 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
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_file "magic_t cookie, const char *filename"
57 .Fn magic_buffer "magic_t cookie, const void *buffer, size_t length"
59 .Fn magic_setflags "magic_t cookie, int flags"
61 .Fn magic_check "magic_t cookie, const char *filename"
63 .Fn magic_compile "magic_t cookie, const char *filename"
65 .Fn magic_load "magic_t cookie, const char *filename"
68 operate on the magic database file
71 .Xr magic __FSECTION__ .
75 creates a magic cookie pointer and returns it. It returns NULL if
76 there was an error allocating the magic cookie. The
78 argument specifies how the other magic functions should behave:
79 .Bl -tag -width MAGIC_COMPRESS
83 Print debugging messages to stderr.
85 If the file queried is a symlink, follow it.
87 If the file is compressed, unpack it and look at the contents.
89 If the file is a block or character special device, then open the device
90 and try to look in its contents.
91 .It Dv MAGIC_MIME_TYPE
92 Return a MIME type string, instead of a textual description.
93 .It Dv MAGIC_MIME_ENCODING
94 Return a MIME encoding, instead of a textual description.
96 Return all matches, not just the first.
98 Check the magic database for consistency and print warnings to stderr.
99 .It Dv MAGIC_PRESERVE_ATIME
100 On systems that support
104 attempt to preserve the access time of files analyzed.
106 Don't translate unprintable characters to a \eooo octal representation.
108 Treat operating system errors while trying to open files and follow symlinks
109 as real errors, instead of printing them in the magic buffer.
110 .It Dv MAGIC_NO_CHECK_APPTYPE
113 application type (only on EMX).
114 .It Dv MAGIC_NO_CHECK_ASCII
115 Check for various types of ascii files.
116 .It Dv MAGIC_NO_CHECK_COMPRESS
117 Don't look for, or inside compressed files.
118 .It Dv MAGIC_NO_CHECK_ELF
119 Don't print elf details.
120 .It Dv MAGIC_NO_CHECK_FORTRAN
121 Don't look for fortran sequences inside ascii files.
122 .It Dv MAGIC_NO_CHECK_SOFT
123 Don't consult magic files.
124 .It Dv MAGIC_NO_CHECK_TAR
125 Don't examine tar files.
126 .It Dv MAGIC_NO_CHECK_TOKENS
127 Don't look for known tokens inside ascii files.
128 .It Dv MAGIC_NO_CHECK_TROFF
129 Don't look for troff sequences inside ascii files.
135 .Xr magic __FSECTION__
136 database and deallocates any resources used.
140 function returns a textual explanation of the last error, or NULL if there was
145 function returns the last operating system error number
147 that was encountered by a system call.
151 function returns a textual description of the contents of the
153 argument, or NULL if an error occurred.
156 is NULL, then stdin is used.
160 function returns a textual description of the contents of the
170 described above. Note that using both MIME flags together can also
171 return extra information on the charset.
175 function can be used to check the validity of entries in the colon
176 separated database files passed in as
178 or NULL for the default database. It returns 0 on success and -1 on
183 function can be used to compile the the colon
184 separated list of database files passed in as
186 or NULL for the default database. It returns 0 on success and -1 on
187 failure. The compiled files created are named from the
189 of each file argument with
195 function must be used to load the the colon
196 separated list of database files passed in as
198 or NULL for the default database file
199 before any magic queries can performed.
201 The default database file is named by the MAGIC environment variable. If
202 that variable is not set, the default database file name is __MAGIC__.
206 to the database filename as appropriate.
210 returns a magic cookie on success and NULL on failure setting errno to
211 an appropriate value. It will set errno to EINVAL if an unsupported
212 value for flags was given.
218 functions return 0 on success and -1 on failure.
223 functions return a string on success and NULL on failure. The
225 function returns a textual description of the errors of the above
226 functions, or NULL if there was no error.
229 returns -1 on systems that don't support
234 .Dv MAGIC_PRESERVE_ATIME
237 .Bl -tag -width __MAGIC__.mgc -compact
239 The non-compiled default magic database.
241 The compiled default magic database.
244 .Xr file __CSECTION__ ,
245 .Xr magic __FSECTION__
247 Måns Rullgård Initial libmagic implementation,
249 Christos Zoulas API cleanup, error code and allocation handling.