.\" $File: libmagic.man,v 1.28 2014/03/02 14:47:16 christos Exp $ .\" .\" Copyright (c) Christos Zoulas 2003. .\" All Rights Reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice immediately at the beginning of the file, without modification, .\" this list of conditions, and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR .\" ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .TH LIBMAGIC 3 "January 6, 2012" "" .SH NAME \fBmagic_open\fP, \fBmagic_close\fP, \fBmagic_error\fP, \fBmagic_errno\fP, \fBmagic_descriptor\fP, \fBmagic_buffer\fP, \fBmagic_setflags\fP, \fBmagic_check\fP, \fBmagic_compile\fP, \fBmagic_list\fP, \fBmagic_load\fP, \fBmagic_version\fP \- Magic number recognition library .SH LIBRARY .HP Magic number recognition library (libmagic, -lmagic) .SH SYNOPSIS .nh .na .HP #include .br .HP magic_t \fBmagic_open\fR(\fIint flags\fR) .br .HP void \fBmagic_close\fR(\fImagic_t cookie\fR) .br .HP const char * \fBmagic_error\fR(\fImagic_t cookie\fR) .br .HP int \fBmagic_errno\fR(\fImagic_t cookie\fR) .br .HP const char * \fBmagic_descriptor\fR(\fImagic_t cookie\fR, \fIint fd\fR) .br .HP const char * \fBmagic_file\fR(\fImagic_t cookie\fR, \fIconst char *filename\fR) .br .HP const char * \fBmagic_buffer\fR(\fImagic_t cookie\fR, \fIconst void *buffer\fR, \fIsize_t length\fR) .br .HP int \fBmagic_setflags\fR(\fImagic_t cookie\fR, \fIint flags\fR) .br .HP int \fBmagic_check\fR(\fImagic_t cookie\fR, \fIconst char *filename\fR) .br .HP int \fBmagic_compile\fR(\fImagic_t cookie\fR, \fIconst char *filename\fR) .br .HP int \fBmagic_list\fR(\fImagic_t cookie\fR, \fIconst char *filename\fR) .br .HP int \fBmagic_load\fR(\fImagic_t cookie\fR, \fIconst char *filename\fR) .br .HP int \fBmagic_version\fR(\fIvoid\fR) .br .ad .hy .SH DESCRIPTION These functions operate on the magic database file which is described in \fBmagic\fP(4). The function \fBmagic_open\fR() creates a magic cookie pointer and returns it. It returns \fBNULL\fR if there was an error allocating the magic cookie. The \fIflags\fP argument specifies how the other magic functions should behave: .TP \fBMAGIC_NONE\fR No special handling. .TP \fBMAGIC_DEBUG\fR Print debugging messages to stderr. .TP \fBMAGIC_SYMLINK\fR If the file queried is a symlink, follow it. .TP \fBMAGIC_COMPRESS\fR If the file is compressed, unpack it and look at the contents. .TP \fBMAGIC_DEVICES\fR If the file is a block or character special device, then open the device and try to look in its contents. .TP \fBMAGIC_MIME_TYPE\fR Return a MIME type string, instead of a textual description. .TP \fBMAGIC_MIME_ENCODING\fR Return a MIME encoding, instead of a textual description. .TP \fBMAGIC_MIME\fR A shorthand for MAGIC_MIME_TYPE | MAGIC_MIME_ENCODING. .TP \fBMAGIC_CONTINUE\fR Return all matches, not just the first. .TP \fBMAGIC_CHECK\fR Check the magic database for consistency and print warnings to stderr. .TP \fBMAGIC_PRESERVE_ATIME\fR On systems that support \fButime\fP(3) or \fButimes\fP(2), attempt to preserve the access time of files analysed. .TP \fBMAGIC_RAW\fR Don't translate unprintable characters to a \eooo octal representation. .TP \fBMAGIC_ERROR\fR Treat operating system errors while trying to open files and follow symlinks as real errors, instead of printing them in the magic buffer. .TP \fBMAGIC_APPLE\fR Return the Apple creator and type. .TP \fBMAGIC_NO_CHECK_APPTYPE\fR Don't check for \fBEMX\fR application type (only on EMX). .TP \fBMAGIC_NO_CHECK_CDF\fR Don't get extra information on MS Composite Document Files. .TP \fBMAGIC_NO_CHECK_COMPRESS\fR Don't look inside compressed files. .TP \fBMAGIC_NO_CHECK_ELF\fR Don't print ELF details. .TP \fBMAGIC_NO_CHECK_ENCODING\fR Don't check text encodings. .TP \fBMAGIC_NO_CHECK_SOFT\fR Don't consult magic files. .TP \fBMAGIC_NO_CHECK_TAR\fR Don't examine tar files. .TP \fBMAGIC_NO_CHECK_TEXT\fR Don't check for various types of text files. .TP \fBMAGIC_NO_CHECK_TOKENS\fR Don't look for known tokens inside ascii files. The \fBmagic_close\fR() function closes the \fBmagic\fP(4) database and deallocates any resources used. The \fBmagic_error\fR() function returns a textual explanation of the last error, or \fBNULL\fR if there was no error. The \fBmagic_errno\fR() function returns the last operating system error number (\fBerrno\fP(2)) that was encountered by a system call. The \fBmagic_file\fR() function returns a textual description of the contents of the \fIfilename\fP argument, or \fBNULL\fR if an error occurred. If the \fIfilename\fP is \fBNULL\fR, then stdin is used. The \fBmagic_descriptor\fR() function returns a textual description of the contents of the \fIfd\fP argument, or \fBNULL\fR if an error occurred. The \fBmagic_buffer\fR() function returns a textual description of the contents of the \fIbuffer\fP argument with \fIlength\fP bytes size. The \fBmagic_setflags\fR() function sets the \fIflags\fP described above. Note that using both MIME flags together can also return extra information on the charset. The \fBmagic_check\fR() function can be used to check the validity of entries in the colon separated database files passed in as \fIfilename\fP, or \fBNULL\fR for the default database. It returns 0 on success and \-1 on failure. The \fBmagic_compile\fR() function can be used to compile the the colon separated list of database files passed in as \fIfilename\fP, or \fBNULL\fR for the default database. It returns 0 on success and \-1 on failure. The compiled files created are named from the \fBbasename\fP(1) of each file argument with ``.mgc'' appended to it. The \fBmagic_list\fR() function dumps all magic entries in a human readable format, dumping first the entries that are matched against binary files and then the ones that match text files. It takes and optional Fa filename argument which is a colon separated list of database files, or \fBNULL\fR for the default database. The \fBmagic_load\fR() function must be used to load the the colon separated list of database files passed in as \fIfilename\fP, or \fBNULL\fR 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 @CLIENT_BASEDIR@/gnu/share/file/magic. \fBmagic_load\fR() adds ``.mgc'' to the database filename as appropriate. The \fBmagic_version\fR() command returns the version number of this library which is compiled into the shared library using the constant \fBMAGIC_VERSION\fR from . This can be used by client programs to verify that the version they compile against is the same as the version that they run against. .SH RETURN VALUES The function \fBmagic_open\fR() returns a magic cookie on success and \fBNULL\fR on failure setting errno to an appropriate value. It will set errno to Er EINVAL if an unsupported value for flags was given. The \fBmagic_list\fR(), \fBmagic_load\fR(), \fBmagic_compile\fR(), and \fBmagic_check\fR() functions return 0 on success and \-1 on failure. The \fBmagic_buffer\fR(), \fBmagic_getpath\fR(), and \fBmagic_file\fR(), functions return a string on success and \fBNULL\fR on failure. The \fBmagic_error\fR() function returns a textual description of the errors of the above functions, or \fBNULL\fR if there was no error. The \fBmagic_version\fR() always returns the version number of the library. Finally, \fBmagic_setflags\fR() returns \-1 on systems that don't support \fButime\fP(3), or \fButimes\fP(2) when \fBMAGIC_PRESERVE_ATIME\fR is set. .SH FILES .TP .B @CLIENT_BASEDIR@/gnu/share/file/magic The non-compiled default magic database. .TP .B @CLIENT_BASEDIR@/gnu/share/file/magic.mgc The compiled default magic database. .SH SEE ALSO \fBfile\fP(1), \fBmagic\fP(4) .SH AUTHORS M\(oans Rullg\(oard Initial libmagic implementation, and configuration. Christos Zoulas API cleanup, error code and allocation handling.