magic_t
magic_open(
int flags
)
void
magic_close(
magic_t cookie
)
const
char
*
magic_error(
magic_t cookie
)
int
magic_errno(
magic_t cookie
)
const
char
*
magic_file(
magic_t cookie, const char *filename
)
const
char
*
magic_buffer(
magic_t cookie, const void *buffer, size_t length
)
int
magic_setflags(
magic_t cookie, int flags
)
int
magic_check(
magic_t cookie, const char *filename
)
int
magic_compile(
magic_t cookie, const char *filename
)
int
magic_load(
magic_t cookie, const char *filename
)
The function
magic_open()
creates a magic cookie pointer and returns it. It returns NULL if
there was an error allocating the magic cookie. The
flags
argument specifies how the other magic functions should behave:
MAGIC_NONE
MAGIC_DEBUG
MAGIC_SYMLINK
MAGIC_COMPRESS
MAGIC_DEVICES
MAGIC_MIME_TYPE
MAGIC_MIME_ENCODING
MAGIC_CONTINUE
MAGIC_CHECK
MAGIC_PRESERVE_ATIME
MAGIC_RAW
MAGIC_ERROR
MAGIC_NO_CHECK_APPTYPE
EMX
application type (only on EMX).
MAGIC_NO_CHECK_ASCII
MAGIC_NO_CHECK_COMPRESS
MAGIC_NO_CHECK_ELF
MAGIC_NO_CHECK_FORTRAN
MAGIC_NO_CHECK_SOFT
MAGIC_NO_CHECK_TAR
MAGIC_NO_CHECK_TOKENS
MAGIC_NO_CHECK_TROFF
The
magic_close()
function closes the
magic(4)
database and deallocates any resources used.
The
magic_error()
function returns a textual explanation of the last error, or NULL if there was
no error.
The
magic_errno()
function returns the last operating system error number
(errno(2))
that was encountered by a system call.
The
magic_file()
function returns a textual description of the contents of the
filename
argument, or NULL if an error occurred.
If the
filename
is NULL, then stdin is used.
The
magic_buffer()
function returns a textual description of the contents of the
buffer
argument with
length
bytes size.
The
magic_setflags()
function sets the
flags
described above. Note that using both MIME flags together can also
return extra information on the charset.
The
magic_check()
function can be used to check the validity of entries in the colon
separated database files passed in as
filename,
or NULL for the default database. It returns 0 on success and -1 on
failure.
The
magic_compile()
function can be used to compile the the colon
separated list of database files passed in as
filename,
or NULL for the default database. It returns 0 on success and -1 on
failure. The compiled files created are named from the
basename(1)
of each file argument with
``.mgc''
appended to it.
The
magic_load()
function must be used to load the the colon
separated list of database files passed in as
filename,
or NULL for the default database file
before any magic queries can performed.
The default database file is named by the MAGIC environment variable. If that variable is not set, the default database file name is /usr/tools/share/file/magic.
magic_load()
adds
``.mime''
and/or
``.mgc''
to the database filename as appropriate.
)
returns a magic cookie on success and NULL on failure setting errno to
an appropriate value. It will set errno to EINVAL if an unsupported
value for flags was given.
The
magic_load(
),
magic_compile(
),
and
magic_check(
)
functions return 0 on success and -1 on failure.
The
magic_file(
),
and
magic_buffer(
)
functions return a string on success and NULL on failure. The
magic_error(
)
function returns a textual description of the errors of the above
functions, or NULL if there was no error.
Finally,
magic_setflags(
)
returns -1 on systems that don't support
utime(2),
or
utimes(2)
when
MAGIC_PRESERVE_ATIME
is set.
/usr/tools/share/file/magic.mime
/usr/tools/share/file/magic.mime.mgc
/usr/tools/share/file/magic
/usr/tools/share/file/magic.mgc