xref: /freebsd/contrib/file/doc/libmagic.man (revision ae316d1d1cffd71ab7751f94e10118777a88e027)
1*ae316d1dSXin LI.\" $File: libmagic.man,v 1.50 2023/12/29 18:04:47 christos Exp $
2b6cee71dSXin LI.\"
3898496eeSXin LI.\" Copyright (c) Christos Zoulas 2003, 2018, 2022
4b6cee71dSXin LI.\" All Rights Reserved.
5b6cee71dSXin LI.\"
6b6cee71dSXin LI.\" Redistribution and use in source and binary forms, with or without
7b6cee71dSXin LI.\" modification, are permitted provided that the following conditions
8b6cee71dSXin LI.\" are met:
9b6cee71dSXin LI.\" 1. Redistributions of source code must retain the above copyright
10b6cee71dSXin LI.\"    notice immediately at the beginning of the file, without modification,
11b6cee71dSXin LI.\"    this list of conditions, and the following disclaimer.
12b6cee71dSXin LI.\" 2. Redistributions in binary form must reproduce the above copyright
13b6cee71dSXin LI.\"    notice, this list of conditions and the following disclaimer in the
14b6cee71dSXin LI.\"    documentation and/or other materials provided with the distribution.
15b6cee71dSXin LI.\"
16b6cee71dSXin LI.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17b6cee71dSXin LI.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18b6cee71dSXin LI.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19b6cee71dSXin LI.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20b6cee71dSXin LI.\" ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21b6cee71dSXin LI.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22b6cee71dSXin LI.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23b6cee71dSXin LI.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24b6cee71dSXin LI.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25b6cee71dSXin LI.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26b6cee71dSXin LI.\" SUCH DAMAGE.
27b6cee71dSXin LI.\"
28*ae316d1dSXin LI.Dd December 29, 2023
29b6cee71dSXin LI.Dt LIBMAGIC 3
30b6cee71dSXin LI.Os
31b6cee71dSXin LI.Sh NAME
32b6cee71dSXin LI.Nm magic_open ,
33b6cee71dSXin LI.Nm magic_close ,
34b6cee71dSXin LI.Nm magic_error ,
35b6cee71dSXin LI.Nm magic_errno ,
36b6cee71dSXin LI.Nm magic_descriptor ,
37b6cee71dSXin LI.Nm magic_buffer ,
3840427ccaSGordon Tetlow.Nm magic_getflags ,
39b6cee71dSXin LI.Nm magic_setflags ,
40b6cee71dSXin LI.Nm magic_check ,
41b6cee71dSXin LI.Nm magic_compile ,
42b6cee71dSXin LI.Nm magic_list ,
43b6cee71dSXin LI.Nm magic_load ,
44c2931133SXin LI.Nm magic_load_buffers ,
45c2931133SXin LI.Nm magic_setparam ,
46c2931133SXin LI.Nm magic_getparam ,
47b6cee71dSXin LI.Nm magic_version
48b6cee71dSXin LI.Nd Magic number recognition library
49b6cee71dSXin LI.Sh LIBRARY
50b6cee71dSXin LI.Lb libmagic
51b6cee71dSXin LI.Sh SYNOPSIS
52b6cee71dSXin LI.In magic.h
53b6cee71dSXin LI.Ft magic_t
54b6cee71dSXin LI.Fn magic_open "int flags"
55b6cee71dSXin LI.Ft void
56b6cee71dSXin LI.Fn magic_close "magic_t cookie"
57b6cee71dSXin LI.Ft const char *
58b6cee71dSXin LI.Fn magic_error "magic_t cookie"
59b6cee71dSXin LI.Ft int
60b6cee71dSXin LI.Fn magic_errno "magic_t cookie"
61b6cee71dSXin LI.Ft const char *
62b6cee71dSXin LI.Fn magic_descriptor "magic_t cookie" "int fd"
63b6cee71dSXin LI.Ft const char *
64b6cee71dSXin LI.Fn magic_file "magic_t cookie" "const char *filename"
65b6cee71dSXin LI.Ft const char *
66b6cee71dSXin LI.Fn magic_buffer "magic_t cookie" "const void *buffer" "size_t length"
67b6cee71dSXin LI.Ft int
6840427ccaSGordon Tetlow.Fn magic_getflags "magic_t cookie"
6940427ccaSGordon Tetlow.Ft int
70b6cee71dSXin LI.Fn magic_setflags "magic_t cookie" "int flags"
71b6cee71dSXin LI.Ft int
72b6cee71dSXin LI.Fn magic_check "magic_t cookie" "const char *filename"
73b6cee71dSXin LI.Ft int
74b6cee71dSXin LI.Fn magic_compile "magic_t cookie" "const char *filename"
75b6cee71dSXin LI.Ft int
76b6cee71dSXin LI.Fn magic_list "magic_t cookie" "const char *filename"
77b6cee71dSXin LI.Ft int
78b6cee71dSXin LI.Fn magic_load "magic_t cookie" "const char *filename"
79b6cee71dSXin LI.Ft int
80c2931133SXin LI.Fn magic_load_buffers "magic_t cookie" "void **buffers" "size_t *sizes" "size_t nbuffers"
81c2931133SXin LI.Ft int
82c2931133SXin LI.Fn magic_getparam "magic_t cookie" "int param" "void *value"
83c2931133SXin LI.Ft int
84c2931133SXin LI.Fn magic_setparam "magic_t cookie" "int param" "const void *value"
85c2931133SXin LI.Ft int
86b6cee71dSXin LI.Fn magic_version "void"
87898496eeSXin LI.Ft const char *
88898496eeSXin LI.Fn magic_getpath "const char *magicfile" "int action"
89b6cee71dSXin LI.Sh DESCRIPTION
90b6cee71dSXin LIThese functions
91b6cee71dSXin LIoperate on the magic database file
92b6cee71dSXin LIwhich is described
93b6cee71dSXin LIin
94b6cee71dSXin LI.Xr magic __FSECTION__ .
95b6cee71dSXin LI.Pp
96b6cee71dSXin LIThe function
97b6cee71dSXin LI.Fn magic_open
98b6cee71dSXin LIcreates a magic cookie pointer and returns it.
99b6cee71dSXin LIIt returns
100b6cee71dSXin LI.Dv NULL
101b6cee71dSXin LIif there was an error allocating the magic cookie.
102b6cee71dSXin LIThe
103b6cee71dSXin LI.Ar flags
104b6cee71dSXin LIargument specifies how the other magic functions should behave:
105b6cee71dSXin LI.Bl -tag -width MAGIC_COMPRESS
106b6cee71dSXin LI.It Dv MAGIC_NONE
107b6cee71dSXin LINo special handling.
108b6cee71dSXin LI.It Dv MAGIC_DEBUG
109b6cee71dSXin LIPrint debugging messages to stderr.
110b6cee71dSXin LI.It Dv MAGIC_SYMLINK
111b6cee71dSXin LIIf the file queried is a symlink, follow it.
112b6cee71dSXin LI.It Dv MAGIC_COMPRESS
113b6cee71dSXin LIIf the file is compressed, unpack it and look at the contents.
114b6cee71dSXin LI.It Dv MAGIC_DEVICES
115b6cee71dSXin LIIf the file is a block or character special device, then open the device
116b6cee71dSXin LIand try to look in its contents.
117b6cee71dSXin LI.It Dv MAGIC_MIME_TYPE
118b6cee71dSXin LIReturn a MIME type string, instead of a textual description.
119b6cee71dSXin LI.It Dv MAGIC_MIME_ENCODING
120b6cee71dSXin LIReturn a MIME encoding, instead of a textual description.
121b6cee71dSXin LI.It Dv MAGIC_MIME
122b6cee71dSXin LIA shorthand for MAGIC_MIME_TYPE | MAGIC_MIME_ENCODING.
123b6cee71dSXin LI.It Dv MAGIC_CONTINUE
124b6cee71dSXin LIReturn all matches, not just the first.
125b6cee71dSXin LI.It Dv MAGIC_CHECK
126b6cee71dSXin LICheck the magic database for consistency and print warnings to stderr.
127b6cee71dSXin LI.It Dv MAGIC_PRESERVE_ATIME
128b6cee71dSXin LIOn systems that support
129b6cee71dSXin LI.Xr utime 3
130b6cee71dSXin LIor
131b6cee71dSXin LI.Xr utimes 2 ,
132b6cee71dSXin LIattempt to preserve the access time of files analysed.
133b6cee71dSXin LI.It Dv MAGIC_RAW
134b6cee71dSXin LIDon't translate unprintable characters to a \eooo octal representation.
135b6cee71dSXin LI.It Dv MAGIC_ERROR
136b6cee71dSXin LITreat operating system errors while trying to open files and follow symlinks
137b6cee71dSXin LIas real errors, instead of printing them in the magic buffer.
138b6cee71dSXin LI.It Dv MAGIC_APPLE
139b6cee71dSXin LIReturn the Apple creator and type.
1405f0216bdSXin LI.It Dv MAGIC_EXTENSION
1415f0216bdSXin LIReturn a slash-separated list of extensions for this file type.
1425f0216bdSXin LI.It Dv MAGIC_COMPRESS_TRANSP
1435f0216bdSXin LIDon't report on compression, only report about the uncompressed data.
144b6cee71dSXin LI.It Dv MAGIC_NO_CHECK_APPTYPE
145b6cee71dSXin LIDon't check for
146b6cee71dSXin LI.Dv EMX
147b6cee71dSXin LIapplication type (only on EMX).
148898496eeSXin LI.It Dv MAGIC_NO_COMPRESS_FORK
149898496eeSXin LIDon't allow decompressors that use fork.
150b6cee71dSXin LI.It Dv MAGIC_NO_CHECK_CDF
151b6cee71dSXin LIDon't get extra information on MS Composite Document Files.
152b6cee71dSXin LI.It Dv MAGIC_NO_CHECK_COMPRESS
153b6cee71dSXin LIDon't look inside compressed files.
154b6cee71dSXin LI.It Dv MAGIC_NO_CHECK_ELF
155b6cee71dSXin LIDon't print ELF details.
156b6cee71dSXin LI.It Dv MAGIC_NO_CHECK_ENCODING
157b6cee71dSXin LIDon't check text encodings.
158b6cee71dSXin LI.It Dv MAGIC_NO_CHECK_SOFT
159b6cee71dSXin LIDon't consult magic files.
160b6cee71dSXin LI.It Dv MAGIC_NO_CHECK_TAR
161b6cee71dSXin LIDon't examine tar files.
162b6cee71dSXin LI.It Dv MAGIC_NO_CHECK_TEXT
163b6cee71dSXin LIDon't check for various types of text files.
164b6cee71dSXin LI.It Dv MAGIC_NO_CHECK_TOKENS
165b6cee71dSXin LIDon't look for known tokens inside ascii files.
16648c779cdSXin LI.It Dv MAGIC_NO_CHECK_JSON
167d38c30c0SXin LIDon't examine JSON files.
168d38c30c0SXin LI.It Dv MAGIC_NO_CHECK_CSV
169d38c30c0SXin LIDon't examine CSV files.
170898496eeSXin LI.It Dv MAGIC_NO_CHECK_SIMH
171898496eeSXin LIDon't examine SIMH tape files.
172b6cee71dSXin LI.El
173b6cee71dSXin LI.Pp
174b6cee71dSXin LIThe
175b6cee71dSXin LI.Fn magic_close
176b6cee71dSXin LIfunction closes the
177b6cee71dSXin LI.Xr magic __FSECTION__
178b6cee71dSXin LIdatabase and deallocates any resources used.
179b6cee71dSXin LI.Pp
180b6cee71dSXin LIThe
181b6cee71dSXin LI.Fn magic_error
182b6cee71dSXin LIfunction returns a textual explanation of the last error, or
183b6cee71dSXin LI.Dv NULL
184b6cee71dSXin LIif there was no error.
185b6cee71dSXin LI.Pp
186b6cee71dSXin LIThe
187b6cee71dSXin LI.Fn magic_errno
188b6cee71dSXin LIfunction returns the last operating system error number
189b6cee71dSXin LI.Pq Xr errno 2
190b6cee71dSXin LIthat was encountered by a system call.
191b6cee71dSXin LI.Pp
192b6cee71dSXin LIThe
193b6cee71dSXin LI.Fn magic_file
194b6cee71dSXin LIfunction returns a textual description of the contents of the
195b6cee71dSXin LI.Ar filename
196b6cee71dSXin LIargument, or
197b6cee71dSXin LI.Dv NULL
198b6cee71dSXin LIif an error occurred.
199b6cee71dSXin LIIf the
200b6cee71dSXin LI.Ar filename
201b6cee71dSXin LIis
202b6cee71dSXin LI.Dv NULL ,
203b6cee71dSXin LIthen stdin is used.
204b6cee71dSXin LI.Pp
205b6cee71dSXin LIThe
206b6cee71dSXin LI.Fn magic_descriptor
207b6cee71dSXin LIfunction returns a textual description of the contents of the
208b6cee71dSXin LI.Ar fd
209b6cee71dSXin LIargument, or
210b6cee71dSXin LI.Dv NULL
211b6cee71dSXin LIif an error occurred.
212b6cee71dSXin LI.Pp
213b6cee71dSXin LIThe
214b6cee71dSXin LI.Fn magic_buffer
215b6cee71dSXin LIfunction returns a textual description of the contents of the
216b6cee71dSXin LI.Ar buffer
217b6cee71dSXin LIargument with
218b6cee71dSXin LI.Ar length
219b6cee71dSXin LIbytes size.
220b6cee71dSXin LI.Pp
221b6cee71dSXin LIThe
22240427ccaSGordon Tetlow.Fn magic_getflags
22340427ccaSGordon Tetlowfunctions returns a value representing current
22440427ccaSGordon Tetlow.Ar flags
22540427ccaSGordon Tetlowset.
22640427ccaSGordon Tetlow.Pp
22740427ccaSGordon TetlowThe
228b6cee71dSXin LI.Fn magic_setflags
229b6cee71dSXin LIfunction sets the
230b6cee71dSXin LI.Ar flags
231b6cee71dSXin LIdescribed above.
232b6cee71dSXin LINote that using both MIME flags together can also
233b6cee71dSXin LIreturn extra information on the charset.
234b6cee71dSXin LI.Pp
235b6cee71dSXin LIThe
236b6cee71dSXin LI.Fn magic_check
237b6cee71dSXin LIfunction can be used to check the validity of entries in the colon
238b6cee71dSXin LIseparated database files passed in as
239b6cee71dSXin LI.Ar filename ,
240b6cee71dSXin LIor
241b6cee71dSXin LI.Dv NULL
242b6cee71dSXin LIfor the default database.
243b6cee71dSXin LIIt returns 0 on success and \-1 on failure.
244b6cee71dSXin LI.Pp
245b6cee71dSXin LIThe
246b6cee71dSXin LI.Fn magic_compile
2473e41d09dSXin LIfunction can be used to compile the colon
248b6cee71dSXin LIseparated list of database files passed in as
249b6cee71dSXin LI.Ar filename ,
250b6cee71dSXin LIor
251b6cee71dSXin LI.Dv NULL
252b6cee71dSXin LIfor the default database.
253b6cee71dSXin LIIt returns 0 on success and \-1 on failure.
254b6cee71dSXin LIThe compiled files created are named from the
255b6cee71dSXin LI.Xr basename 1
256b6cee71dSXin LIof each file argument with
257b6cee71dSXin LI.Dq .mgc
258b6cee71dSXin LIappended to it.
259b6cee71dSXin LI.Pp
260b6cee71dSXin LIThe
261b6cee71dSXin LI.Fn magic_list
262b6cee71dSXin LIfunction dumps all magic entries in a human readable format,
263b6cee71dSXin LIdumping first the entries that are matched against binary files and then the
264b6cee71dSXin LIones that match text files.
265b6cee71dSXin LIIt takes and optional
266b6cee71dSXin LI.Fa filename
267b6cee71dSXin LIargument which is a colon separated list of database files, or
268b6cee71dSXin LI.Dv NULL
269b6cee71dSXin LIfor the default database.
270b6cee71dSXin LI.Pp
271b6cee71dSXin LIThe
272b6cee71dSXin LI.Fn magic_load
2733e41d09dSXin LIfunction must be used to load the colon
274b6cee71dSXin LIseparated list of database files passed in as
275b6cee71dSXin LI.Ar filename ,
276b6cee71dSXin LIor
277b6cee71dSXin LI.Dv NULL
278b6cee71dSXin LIfor the default database file before any magic queries can performed.
279b6cee71dSXin LI.Pp
280b6cee71dSXin LIThe default database file is named by the MAGIC environment variable.
281b6cee71dSXin LIIf that variable is not set, the default database file name is __MAGIC__.
282b6cee71dSXin LI.Fn magic_load
283b6cee71dSXin LIadds
284b6cee71dSXin LI.Dq .mgc
285b6cee71dSXin LIto the database filename as appropriate.
286b6cee71dSXin LI.Pp
287b6cee71dSXin LIThe
288c2931133SXin LI.Fn magic_load_buffers
289c2931133SXin LIfunction takes an array of size
290c2931133SXin LI.Fa nbuffers
291c2931133SXin LIof
292c2931133SXin LI.Fa buffers
293c2931133SXin LIwith a respective size for each in the array of
294c2931133SXin LI.Fa sizes
295c2931133SXin LIloaded with the contents of the magic databases from the filesystem.
296c2931133SXin LIThis function can be used in environment where the magic library does
297c2931133SXin LInot have direct access to the filesystem, but can access the magic
298c2931133SXin LIdatabase via shared memory or other IPC means.
299c2931133SXin LI.Pp
300c2931133SXin LIThe
301c2931133SXin LI.Fn magic_getparam
302c2931133SXin LIand
303c2931133SXin LI.Fn magic_setparam
3043e41d09dSXin LIallow getting and setting various limits related to the magic
305c2931133SXin LIlibrary.
306c2931133SXin LI.Bl -column "MAGIC_PARAM_ELF_PHNUM_MAX" "size_t" "Default" -offset indent
307c2931133SXin LI.It Sy "Parameter" Ta Sy "Type" Ta Sy "Default"
308c2931133SXin LI.It Li MAGIC_PARAM_INDIR_MAX Ta size_t Ta 15
309c2931133SXin LI.It Li MAGIC_PARAM_NAME_MAX Ta size_t Ta 30
3104460e5b0SXin LI.It Li MAGIC_PARAM_ELF_NOTES_MAX Ta size_t Ta 256
311c2931133SXin LI.It Li MAGIC_PARAM_ELF_PHNUM_MAX Ta size_t Ta 128
312c2931133SXin LI.It Li MAGIC_PARAM_ELF_SHNUM_MAX Ta size_t Ta 32768
3139ce06829SXin LI.It Li MAGIC_PARAM_REGEX_MAX Ta size_t Ta 8192
314*ae316d1dSXin LI.It Li MAGIC_PARAM_BYTES_MAX Ta size_t Ta 7340032
315*ae316d1dSXin LI.It Li MAGIC_PARAM_ENCODING_MAX Ta size_t Ta 1048576
316*ae316d1dSXin LI.It Li MAGIC_PARAM_ELF_SHSIZE_MAX Ta size_t Ta 134217728
317*ae316d1dSXin LI.It Li MAGIC_PARAM_MAGWARN_MAX Ta size_t Ta 64
318c2931133SXin LI.El
319c2931133SXin LI.Pp
320c2931133SXin LIThe
321c2931133SXin LI.Dv MAGIC_PARAM_INDIR_RECURSION
322c2931133SXin LIparameter controls how many levels of recursion will be followed for
323c2931133SXin LIindirect magic entries.
324c2931133SXin LI.Pp
325c2931133SXin LIThe
326c2931133SXin LI.Dv MAGIC_PARAM_NAME_RECURSION
327c2931133SXin LIparameter controls how many levels of recursion will be followed for
328c2931133SXin LIfor name/use calls.
329c2931133SXin LI.Pp
330c2931133SXin LIThe
331c2931133SXin LI.Dv MAGIC_PARAM_NAME_MAX
332c2931133SXin LIparameter controls the maximum number of calls for name/use.
333c2931133SXin LI.Pp
334c2931133SXin LIThe
3354460e5b0SXin LI.Dv MAGIC_PARAM_NOTES_MAX
3364460e5b0SXin LIparameter controls how many ELF notes will be processed.
3374460e5b0SXin LI.Pp
3384460e5b0SXin LIThe
339c2931133SXin LI.Dv MAGIC_PARAM_PHNUM_MAX
3404460e5b0SXin LIparameter controls how many ELF program sections will be processed.
341c2931133SXin LI.Pp
342c2931133SXin LIThe
343c2931133SXin LI.Dv MAGIC_PARAM_SHNUM_MAX
3444460e5b0SXin LIparameter controls how many ELF sections will be processed.
345c2931133SXin LI.Pp
346c2931133SXin LIThe
347*ae316d1dSXin LI.Dv MAGIC_PARAM_REGEX_MAX
348*ae316d1dSXin LIparameter controls the maximum length for regex searches.
349*ae316d1dSXin LI.Pp
350*ae316d1dSXin LIThe
351*ae316d1dSXin LI.Dv MAGIC_PARAM_BYTES_MAX
352*ae316d1dSXin LIparameter controls the maximum number of bytes to look inside a file.
353*ae316d1dSXin LI.Pp
354*ae316d1dSXin LIThe
355*ae316d1dSXin LI.Dv MAGIC_PARAM_ENCODING_MAX
356*ae316d1dSXin LIparameter controls the maximum number of bytes to scan for encoding detection.
357*ae316d1dSXin LI.Pp
358*ae316d1dSXin LIThe
359*ae316d1dSXin LI.Dv MAGIC_PARAM_ELF_SHSIZE_MAX
360*ae316d1dSXin LIparameter controls the maximum number of bytes in an elf section.
361*ae316d1dSXin LI.Pp
362*ae316d1dSXin LIThe
363*ae316d1dSXin LI.Dv MAGIC_PARAM_MAGWARN_MAX
364*ae316d1dSXin LIparameter controls the maximum number of warnings to tolerate in a magic file.
365*ae316d1dSXin LI.Pp
366*ae316d1dSXin LIThe
367b6cee71dSXin LI.Fn magic_version
368b6cee71dSXin LIcommand returns the version number of this library which is compiled into
369b6cee71dSXin LIthe shared library using the constant
370b6cee71dSXin LI.Dv MAGIC_VERSION
371b6cee71dSXin LIfrom
372b6cee71dSXin LI.In magic.h .
373b6cee71dSXin LIThis can be used by client programs to verify that the version they compile
374b6cee71dSXin LIagainst is the same as the version that they run against.
375898496eeSXin LI.Pp
376898496eeSXin LIThe
377898496eeSXin LI.Fn magic_getpath
378898496eeSXin LIcommand returns the colon separated list of magic database locations.
379898496eeSXin LIIf the
380898496eeSXin LI.Fa filename
381898496eeSXin LIis non-NULL, then it is returned.
382898496eeSXin LIOtherwise, if the
383898496eeSXin LI.Dv MAGIC
384898496eeSXin LIenvironment variable is defined, then it is returned.
385898496eeSXin LIOtherwise, if
386898496eeSXin LI.Fa action
387898496eeSXin LIis 0 (meaning "file load"), then any user-specific magic database file is included.
388898496eeSXin LIOtherwise, only the system default magic database path is included.
389b6cee71dSXin LI.Sh RETURN VALUES
390b6cee71dSXin LIThe function
391b6cee71dSXin LI.Fn magic_open
392b6cee71dSXin LIreturns a magic cookie on success and
393b6cee71dSXin LI.Dv NULL
394b6cee71dSXin LIon failure setting errno to an appropriate value.
395b6cee71dSXin LIIt will set errno to
396b6cee71dSXin LI.Er EINVAL
397b6cee71dSXin LIif an unsupported value for flags was given.
398b6cee71dSXin LIThe
399b6cee71dSXin LI.Fn magic_list ,
400b6cee71dSXin LI.Fn magic_load ,
401b6cee71dSXin LI.Fn magic_compile ,
402b6cee71dSXin LIand
403b6cee71dSXin LI.Fn magic_check
404b6cee71dSXin LIfunctions return 0 on success and \-1 on failure.
405b6cee71dSXin LIThe
406b6cee71dSXin LI.Fn magic_buffer ,
407b6cee71dSXin LI.Fn magic_getpath ,
408b6cee71dSXin LIand
409b6cee71dSXin LI.Fn magic_file ,
410b6cee71dSXin LIfunctions return a string on success and
411b6cee71dSXin LI.Dv NULL
412b6cee71dSXin LIon failure.
413b6cee71dSXin LIThe
414b6cee71dSXin LI.Fn magic_error
415b6cee71dSXin LIfunction returns a textual description of the errors of the above
416b6cee71dSXin LIfunctions, or
417b6cee71dSXin LI.Dv NULL
418b6cee71dSXin LIif there was no error.
419b6cee71dSXin LIThe
420b6cee71dSXin LI.Fn magic_version
421b6cee71dSXin LIalways returns the version number of the library.
422b6cee71dSXin LIFinally,
423b6cee71dSXin LI.Fn magic_setflags
424b6cee71dSXin LIreturns \-1 on systems that don't support
425b6cee71dSXin LI.Xr utime 3 ,
426b6cee71dSXin LIor
427b6cee71dSXin LI.Xr utimes 2
428b6cee71dSXin LIwhen
429b6cee71dSXin LI.Dv MAGIC_PRESERVE_ATIME
430b6cee71dSXin LIis set.
431b6cee71dSXin LI.Sh FILES
432b6cee71dSXin LI.Bl -tag -width __MAGIC__.mgc -compact
433b6cee71dSXin LI.It Pa __MAGIC__
434b6cee71dSXin LIThe non-compiled default magic database.
435b6cee71dSXin LI.It Pa __MAGIC__.mgc
436b6cee71dSXin LIThe compiled default magic database.
437b6cee71dSXin LI.El
438b6cee71dSXin LI.Sh SEE ALSO
439b6cee71dSXin LI.Xr file __CSECTION__ ,
440b6cee71dSXin LI.Xr magic __FSECTION__
44148c779cdSXin LI.Sh BUGS
44248c779cdSXin LIThe results from
44348c779cdSXin LI.Fn magic_buffer
44448c779cdSXin LIand
44548c779cdSXin LI.Fn magic_file
44648c779cdSXin LIwhere the buffer and the file contain the same data
44748c779cdSXin LIcan produce different results, because in the
44848c779cdSXin LI.Fn magic_file
44948c779cdSXin LIcase, the program can
45048c779cdSXin LI.Xr lseek 2
45148c779cdSXin LIand
45248c779cdSXin LI.Xr stat 2
45348c779cdSXin LIthe file descriptor.
454b6cee71dSXin LI.Sh AUTHORS
455b6cee71dSXin LI.An M\(oans Rullg\(oard
456b6cee71dSXin LIInitial libmagic implementation, and configuration.
457b6cee71dSXin LI.An Christos Zoulas
458b6cee71dSXin LIAPI cleanup, error code and allocation handling.
459