| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 | .\" $File: libmagic.man,v 1.21 2009/11/24 21:16:14 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..\".Dd November 24, 2009.Dt LIBMAGIC 3.Os.Sh NAME.Nm magic_open ,.Nm magic_close ,.Nm magic_error ,.Nm magic_file ,.Nm magic_buffer ,.Nm magic_setflags ,.Nm magic_check ,.Nm magic_compile ,.Nm magic_load.Nd Magic number recognition library..Sh LIBRARY.Lb libmagic.Sh SYNOPSIS.In magic.h.Ft magic_t.Fn magic_open "int flags".Ft void.Fn magic_close "magic_t cookie".Ft const char *.Fn magic_error "magic_t cookie".Ft int.Fn magic_errno "magic_t cookie".Ft const char *.Fn magic_file "magic_t cookie, const char *filename".Ft const char *.Fn magic_buffer "magic_t cookie, const void *buffer, size_t length".Ft int.Fn magic_setflags "magic_t cookie, int flags".Ft int.Fn magic_check "magic_t cookie, const char *filename".Ft int.Fn magic_compile "magic_t cookie, const char *filename".Ft int.Fn magic_load "magic_t cookie, const char *filename".Sh DESCRIPTIONThese functionsoperate on the magic database filewhich is describedin.Xr magic __FSECTION__ ..PpThe function.Fn magic_opencreates a magic cookie pointer and returns it. It returns NULL ifthere was an error allocating the magic cookie. The.Ar flagsargument specifies how the other magic functions should behave:.Bl -tag -width MAGIC_COMPRESS.It Dv MAGIC_NONENo special handling..It Dv MAGIC_DEBUGPrint debugging messages to stderr..It Dv MAGIC_SYMLINKIf the file queried is a symlink, follow it..It Dv MAGIC_COMPRESSIf the file is compressed, unpack it and look at the contents..It Dv MAGIC_DEVICESIf the file is a block or character special device, then open the deviceand try to look in its contents..It Dv MAGIC_MIME_TYPEReturn a MIME type string, instead of a textual description..It Dv MAGIC_MIME_ENCODINGReturn a MIME encoding, instead of a textual description..It Dv MAGIC_CONTINUEReturn all matches, not just the first..It Dv MAGIC_CHECKCheck the magic database for consistency and print warnings to stderr..It Dv MAGIC_PRESERVE_ATIMEOn systems that support.Xr utime 2or.Xr utimes 2 ,attempt to preserve the access time of files analyzed..It Dv MAGIC_RAWDon't translate unprintable characters to a \eooo octal representation..It Dv MAGIC_ERRORTreat operating system errors while trying to open files and follow symlinksas real errors, instead of printing them in the magic buffer..It Dv MAGIC_NO_CHECK_APPTYPECheck for.Dv EMXapplication type (only on EMX)..It Dv MAGIC_NO_CHECK_ASCIICheck for various types of ascii files..It Dv MAGIC_NO_CHECK_COMPRESSDon't look for, or inside compressed files..It Dv MAGIC_NO_CHECK_ELFDon't print elf details..It Dv MAGIC_NO_CHECK_FORTRANDon't look for fortran sequences inside ascii files..It Dv MAGIC_NO_CHECK_SOFTDon't consult magic files..It Dv MAGIC_NO_CHECK_TARDon't examine tar files..It Dv MAGIC_NO_CHECK_TOKENSDon't look for known tokens inside ascii files..It Dv MAGIC_NO_CHECK_TROFFDon't look for troff sequences inside ascii files..El.PpThe.Fn magic_closefunction closes the.Xr magic __FSECTION__database and deallocates any resources used..PpThe.Fn magic_errorfunction returns a textual explanation of the last error, or NULL if there wasno error..PpThe.Fn magic_errnofunction returns the last operating system error number.Pq Xr errno 2that was encountered by a system call..PpThe.Fn magic_filefunction returns a textual description of the contents of the.Ar filenameargument, or NULL if an error occurred.If the.Ar filenameis NULL, then stdin is used..PpThe.Fn magic_bufferfunction returns a textual description of the contents of the.Ar bufferargument with.Ar lengthbytes size..PpThe.Fn magic_setflagsfunction sets the.Ar flagsdescribed above. Note that using both MIME flags together can alsoreturn extra information on the charset..PpThe.Fn magic_checkfunction can be used to check the validity of entries in the colonseparated database files passed in as.Ar filename ,or NULL for the default database. It returns 0 on success and -1 onfailure..PpThe.Fn magic_compilefunction can be used to compile the the colonseparated list of database files passed in as.Ar filename ,or NULL for the default database. It returns 0 on success and -1 onfailure. The compiled files created are named from the.Xr basename 1of each file argument with.Dq .mgcappended to it..PpThe.Fn magic_loadfunction must be used to load the the colonseparated list of database files passed in as.Ar filename ,or NULL for the default database filebefore any magic queries can performed..PpThe default database file is named by the MAGIC environment variable.  Ifthat variable is not set, the default database file name is __MAGIC__..Fn magic_loadadds.Dq .mgcto the database filename as appropriate..Sh RETURN VALUESThe function.Fn magic_openreturns a magic cookie on success and NULL on failure setting errno toan appropriate value. It will set errno to EINVAL if an unsupportedvalue for flags was given.The.Fn magic_load ,.Fn magic_compile ,and.Fn magic_checkfunctions return 0 on success and -1 on failure.The.Fn magic_file ,and.Fn magic_bufferfunctions return a string on success and NULL on failure. The.Fn magic_errorfunction returns a textual description of the errors of the abovefunctions, or NULL if there was no error.Finally,.Fn magic_setflagsreturns -1 on systems that don't support.Xr utime 2 ,or.Xr utimes 2when.Dv MAGIC_PRESERVE_ATIMEis set..Sh FILES.Bl -tag -width __MAGIC__.mgc -compact.It Pa __MAGIC__The non-compiled default magic database..It Pa __MAGIC__.mgcThe compiled default magic database..El.Sh SEE ALSO.Xr file __CSECTION__ ,.Xr magic __FSECTION__.Sh AUTHORSMåns Rullgård Initial libmagic implementation,and configuration.Christos Zoulas API cleanup, error code and allocation handling.
 |