1 | MAGIC(3) BSD Library Functions Manual MAGIC(3)
|
---|
2 |
|
---|
3 | NAME
|
---|
4 | magic_open, magic_close, magic_error, magic_file,
|
---|
5 | magic_buffer, magic_setflags, magic_check, magic_compile,
|
---|
6 | magic_load -- Magic number recognition library.
|
---|
7 |
|
---|
8 | LIBRARY
|
---|
9 | Magic Number Recognition Library (libmagic, -lmagic)
|
---|
10 |
|
---|
11 | SYNOPSIS
|
---|
12 | #include <magic.h>
|
---|
13 |
|
---|
14 | magic_t
|
---|
15 | magic_open(int flags);
|
---|
16 |
|
---|
17 | void
|
---|
18 | magic_close(magic_t cookie);
|
---|
19 |
|
---|
20 | const char *
|
---|
21 | magic_error(magic_t cookie);
|
---|
22 |
|
---|
23 | int
|
---|
24 | magic_errno(magic_t cookie);
|
---|
25 |
|
---|
26 | const char *
|
---|
27 | magic_file(magic_t cookie, const char *filename);
|
---|
28 |
|
---|
29 | const char *
|
---|
30 | magic_buffer(magic_t cookie, const void *buffer, size_t length);
|
---|
31 |
|
---|
32 | int
|
---|
33 | magic_setflags(magic_t cookie, int flags);
|
---|
34 |
|
---|
35 | int
|
---|
36 | magic_check(magic_t cookie, const char *filename);
|
---|
37 |
|
---|
38 | int
|
---|
39 | magic_compile(magic_t cookie, const char *filename);
|
---|
40 |
|
---|
41 | int
|
---|
42 | magic_load(magic_t cookie, const char *filename);
|
---|
43 |
|
---|
44 | DESCRIPTION
|
---|
45 | These functions operate on the magic database file which
|
---|
46 | is described in magic(5).
|
---|
47 |
|
---|
48 | The function magic_open() creates a magic cookie pointer
|
---|
49 | and returns it. It returns NULL if there was an error
|
---|
50 | allocating the magic cookie. The flags argument specifies
|
---|
51 | how the other magic functions should behave:
|
---|
52 |
|
---|
53 | MAGIC_NONE No special handling.
|
---|
54 |
|
---|
55 | MAGIC_DEBUG Print debugging messages to stderr.
|
---|
56 |
|
---|
57 | MAGIC_SYMLINK If the file queried is a symlink, follow
|
---|
58 | it.
|
---|
59 |
|
---|
60 | MAGIC_COMPRESS If the file is compressed, unpack it and
|
---|
61 | look at the contents.
|
---|
62 |
|
---|
63 | MAGIC_DEVICES If the file is a block or character spe-
|
---|
64 | cial device, then open the device and try
|
---|
65 | to look in its contents.
|
---|
66 |
|
---|
67 | MAGIC_MIME_TYPE
|
---|
68 | Return a MIME type string, instead of a
|
---|
69 | textual description.
|
---|
70 |
|
---|
71 | MAGIC_MIME_ENCODING
|
---|
72 | Return a MIME encoding, instead of a tex-
|
---|
73 | tual description.
|
---|
74 |
|
---|
75 | MAGIC_CONTINUE Return all matches, not just the first.
|
---|
76 |
|
---|
77 | MAGIC_CHECK Check the magic database for consistency
|
---|
78 | and print warnings to stderr.
|
---|
79 |
|
---|
80 | MAGIC_PRESERVE_ATIME
|
---|
81 | On systems that support utime(2) or
|
---|
82 | utimes(2), attempt to preserve the access
|
---|
83 | time of files analyzed.
|
---|
84 |
|
---|
85 | MAGIC_RAW Don't translate unprintable characters to
|
---|
86 | a \ooo octal representation.
|
---|
87 |
|
---|
88 | MAGIC_ERROR Treat operating system errors while trying
|
---|
89 | to open files and follow symlinks as real
|
---|
90 | errors, instead of printing them in the
|
---|
91 | magic buffer.
|
---|
92 |
|
---|
93 | MAGIC_NO_CHECK_APPTYPE
|
---|
94 | Check for EMX application type (only on
|
---|
95 | EMX).
|
---|
96 |
|
---|
97 | MAGIC_NO_CHECK_ASCII
|
---|
98 | Check for various types of ascii files.
|
---|
99 |
|
---|
100 | MAGIC_NO_CHECK_COMPRESS
|
---|
101 | Don't look for, or inside compressed
|
---|
102 | files.
|
---|
103 |
|
---|
104 | MAGIC_NO_CHECK_ELF
|
---|
105 | Don't print elf details.
|
---|
106 |
|
---|
107 | MAGIC_NO_CHECK_FORTRAN
|
---|
108 | Don't look for fortran sequences inside
|
---|
109 | ascii files.
|
---|
110 |
|
---|
111 | MAGIC_NO_CHECK_SOFT
|
---|
112 | Don't consult magic files.
|
---|
113 |
|
---|
114 | MAGIC_NO_CHECK_TAR
|
---|
115 | Don't examine tar files.
|
---|
116 |
|
---|
117 | MAGIC_NO_CHECK_TOKENS
|
---|
118 | Don't look for known tokens inside ascii
|
---|
119 | files.
|
---|
120 |
|
---|
121 | MAGIC_NO_CHECK_TROFF
|
---|
122 | Don't look for troff sequences inside
|
---|
123 | ascii files.
|
---|
124 |
|
---|
125 | The magic_close() function closes the magic(5) database
|
---|
126 | and deallocates any resources used.
|
---|
127 |
|
---|
128 | The magic_error() function returns a textual explanation
|
---|
129 | of the last error, or NULL if there was no error.
|
---|
130 |
|
---|
131 | The magic_errno() function returns the last operating sys-
|
---|
132 | tem error number (errno(2)) that was encountered by a sys-
|
---|
133 | tem call.
|
---|
134 |
|
---|
135 | The magic_file() function returns a textual description of
|
---|
136 | the contents of the filename argument, or NULL if an error
|
---|
137 | occurred. If the filename is NULL, then stdin is used.
|
---|
138 |
|
---|
139 | The magic_buffer() function returns a textual description
|
---|
140 | of the contents of the buffer argument with length bytes
|
---|
141 | size.
|
---|
142 |
|
---|
143 | The magic_setflags() function sets the flags described
|
---|
144 | above. Note that using both MIME flags together can also
|
---|
145 | return extra information on the charset.
|
---|
146 |
|
---|
147 | The magic_check() function can be used to check the valid-
|
---|
148 | ity of entries in the colon separated database files
|
---|
149 | passed in as filename, or NULL for the default database.
|
---|
150 | It returns 0 on success and -1 on failure.
|
---|
151 |
|
---|
152 | The magic_compile() function can be used to compile the
|
---|
153 | the colon separated list of database files passed in as
|
---|
154 | filename, or NULL for the default database. It returns 0
|
---|
155 | on success and -1 on failure. The compiled files created
|
---|
156 | are named from the basename(1) of each file argument with
|
---|
157 | ``.mgc'' appended to it.
|
---|
158 |
|
---|
159 | The magic_load() function must be used to load the the
|
---|
160 | colon separated list of database files passed in as
|
---|
161 | filename, or NULL for the default database file before any
|
---|
162 | magic queries can performed.
|
---|
163 |
|
---|
164 | The default database file is named by the MAGIC environ-
|
---|
165 | ment variable. If that variable is not set, the default
|
---|
166 | database file name is c:/progra~1/file/share/misc/magic.
|
---|
167 | magic_load() adds ``.mgc'' to the database filename as
|
---|
168 | appropriate.
|
---|
169 |
|
---|
170 | RETURN VALUES
|
---|
171 | The function magic_open() returns a magic cookie on suc-
|
---|
172 | cess and NULL on failure setting errno to an appropriate
|
---|
173 | value. It will set errno to EINVAL if an unsupported value
|
---|
174 | for flags was given. The magic_load(), magic_compile(),
|
---|
175 | and magic_check() functions return 0 on success and -1 on
|
---|
176 | failure. The magic_file(), and magic_buffer() functions
|
---|
177 | return a string on success and NULL on failure. The
|
---|
178 | magic_error() function returns a textual description of
|
---|
179 | the errors of the above functions, or NULL if there was no
|
---|
180 | error. Finally, magic_setflags() returns -1 on systems
|
---|
181 | that don't support utime(2), or utimes(2) when
|
---|
182 | MAGIC_PRESERVE_ATIME is set.
|
---|
183 |
|
---|
184 | FILES
|
---|
185 | c:/progra~1/file/share/misc/magic The non-compiled
|
---|
186 | default magic data-
|
---|
187 | base.
|
---|
188 | c:/progra~1/file/share/misc/magic.mgc The compiled
|
---|
189 | default magic data-
|
---|
190 | base.
|
---|
191 |
|
---|
192 | SEE ALSO
|
---|
193 | file(1), magic(5)
|
---|
194 |
|
---|
195 | AUTHORS
|
---|
196 | Måns Rullgård Initial libmagic implementation, and config-
|
---|
197 | uration. Christos Zoulas API cleanup, error code and
|
---|
198 | allocation handling.
|
---|
199 |
|
---|
200 | BSD October 6, 2008 BSD
|
---|