]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/file/libmagic.man
This commit was generated by cvs2svn to compensate for changes in r158795,
[FreeBSD/FreeBSD.git] / contrib / file / libmagic.man
1 .\"
2 .\" Copyright (c) Christos Zoulas 2003.
3 .\" All Rights Reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice immediately at the beginning of the file, without modification,
10 .\"    this list of conditions, and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in the
13 .\"    documentation and/or other materials provided with the distribution.
14 .\" 3. The name of the author may not be used to endorse or promote products
15 .\"    derived from this software without specific prior written permission.
16 .\" 
17 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 .\" ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 .\" SUCH DAMAGE.
28 .\"
29 .Dd March 22, 2003
30 .Dt MAGIC 3
31 .Os
32 .Sh NAME
33 .Nm magic_open ,
34 .Nm magic_close ,
35 .Nm magic_error ,
36 .Nm magic_file ,
37 .Nm magic_buffer ,
38 .Nm magic_setflags ,
39 .Nm magic_check ,
40 .Nm magic_compile ,
41 .Nm magic_load
42 .Nd Magic number recognition library.
43 .Sh LIBRARY
44 .Lb libmagic
45 .Sh SYNOPSIS
46 .In magic.h
47 .Ft magic_t
48 .Fn magic_open "int flags"
49 .Ft void
50 .Fn magic_close "magic_t cookie"
51 .Ft const char *
52 .Fn magic_error "magic_t cookie"
53 .Ft int
54 .Fn magic_errno "magic_t cookie"
55 .Ft const char *
56 .Fn magic_file "magic_t cookie, const char *filename"
57 .Ft const char *
58 .Fn magic_buffer "magic_t cookie, const void *buffer, size_t length"
59 .Ft int
60 .Fn magic_setflags "magic_t cookie, int flags"
61 .Ft int
62 .Fn magic_check "magic_t cookie, const char *filename"
63 .Ft int
64 .Fn magic_compile "magic_t cookie, const char *filename"
65 .Ft int
66 .Fn magic_load "magic_t cookie, const char *filename"
67 .Sh DESCRIPTION
68 These functions
69 operate on the magic database file
70 which is described
71 in
72 .Xr magic __FSECTION__ .
73 .Pp
74 The function
75 .Fn magic_open
76 creates a magic cookie pointer and returns it. It returns NULL if
77 there was an error allocating the magic cookie. The 
78 .Ar flags
79 argument specifies how the other magic functions should behave:
80 .Bl -tag -width MAGIC_COMPRESS
81 .It Dv MAGIC_NONE
82 No special handling.
83 .It Dv MAGIC_DEBUG
84 Print debugging messages to stderr.
85 .It Dv MAGIC_SYMLINK
86 If the file queried is a symlink, follow it.
87 .It Dv MAGIC_COMPRESS
88 If the file is compressed, unpack it and look at the contents.
89 .It Dv MAGIC_DEVICES
90 If the file is a block or character special device, then open the device
91 and try to look in its contents.
92 .It Dv MAGIC_MIME
93 Return a mime string, instead of a textual description.
94 .It Dv MAGIC_CONTINUE
95 Return all matches, not just the first.
96 .It Dv MAGIC_CHECK
97 Check the magic database for consistency and print warnings to stderr.
98 .It Dv MAGIC_PRESERVE_ATIME
99 On systems that support
100 .Xr utime 2
101 or
102 .Xr utimes 2 ,
103 attempt to preserve the access time of files analyzed.
104 .It Dv MAGIC_RAW
105 Don't translate unprintable characters to a \eooo octal representation.
106 .It Dv MAGIC_ERROR
107 Treat operating system errors while trying to open files and follow symlinks
108 as real errors, instead of printing them in the magic buffer.
109 .El
110 .Pp
111 The
112 .Fn magic_close
113 function closes the
114 .Xr magic __FSECTION__
115 database and deallocates any resources used.
116 .Pp
117 The
118 .Fn magic_error
119 function returns a textual explanation of the last error, or NULL if there was
120 no error.
121 .Pp
122 The
123 .Fn magic_errno
124 function returns the last operating system error number (
125 .Xr errno 3 )
126 that was encountered by a system call.
127 .Pp
128 The
129 .Fn magic_file
130 function returns a textual description of the contents of the
131 .Ar filename
132 argument, or NULL if an error occurred.
133 If the
134 .Ar filename
135 is NULL, then stdin is used.
136 .Pp
137 The
138 .Fn magic_buffer
139 function returns a textual description of the contents of the
140 .Ar buffer
141 argument with
142 .Ar length
143 bytes size.
144 .Pp
145 The
146 .Fn magic_setflags
147 function, sets the 
148 .Ar flags
149 described above.
150 .Pp
151 The
152 .Fn magic_check
153 function can be used to check the validity of entries in the colon
154 separated database files passed in as
155 .Ar filename ,
156 or NULL for the default database. It returns 0 on success and -1 on
157 failure.
158 .Pp
159 The
160 .Fn magic_compile
161 function can be used to compile the the colon
162 separated list of database files passed in as
163 .Ar filename ,
164 or NULL for the default database. It returns 0 on success and -1 on
165 failure. The compiled files created are named from the
166 .Xr basename 1
167 of each file argument with ".mgc" appended to it.
168 .Pp
169 The
170 .Fn magic_load
171 function must be used to load the the colon
172 separated list of database files passed in as
173 .Ar filename ,
174 or NULL for the default database file
175 before any magic queries can performed.
176 .Pp
177 The default database file is named by the MAGIC environment variable.  If
178 that variable is not set, the default database file name is __MAGIC__.
179 .Pp
180 .Fn magic_load
181 adds ".mime" and/or ".mgc" to the database filename as appropriate.
182 .Sh RETURN VALUES
183 The function
184 .Fn magic_open
185 returns a magic cookie on success and NULL on failure setting errno to
186 an appropriate value. It will set errno to EINVAL if an unsupported
187 value for flags was given.
188 The
189 .Fn magic_load ,
190 .Fn magic_compile ,
191 and
192 .Fn magic_check
193 functions return 0 on success and -1 on failure.
194 The
195 .Fn magic_file ,
196 and
197 .Fn magic_buffer 
198 functions return a string on success and NULL on failure. The
199 .Fn magic_error
200 function returns a textual description of the errors of the above
201 functions, or NULL if there was no error.
202 Finally,
203 .Fn magic_setflags
204 returns -1 on systems that don't support
205 .Xr utime 2 ,
206 or
207 .Xr utimes 2
208 when
209 .Dv MAGIC_PRESERVE_ATIME
210 is set.
211 .Sh FILES
212 .Bl -tag -width __MAGIC__.mime.mgc -compact
213 .It Pa __MAGIC__.mime
214 The non-compiled default magic mime database.
215 .It Pa __MAGIC__.mime.mgc
216 The compiled default magic mime database.
217 .It Pa __MAGIC__
218 The non-compiled default magic database.
219 .It Pa __MAGIC__.mgc
220 The compiled default magic database.
221 .El
222 .Sh SEE ALSO
223 .Xr file __CSECTION__ ,
224 .Xr magic __FSECTION__ 
225 .Sh AUTHORS
226 Måns Rullgård Initial libmagic implementation,
227 and configuration.
228 Christos Zoulas API cleanup, error code and allocation handling.