LIBMAGIC - Online Linux Manual Page
Section : 3
Updated : November 24, 2009 
 
NAME  magic_open,   magic_close,   magic_error,   magic_file,   magic_buffer,   magic_setflags,   magic_check,   magic_compile,   magic_load  — Magic number recognition library. 
LIBRARYMagic Number Recognition Library (libmagic , -lmagic) 
SYNOPSIS #include <magic.h>  
 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); 
DESCRIPTIONThese functions operate on the magic database file which is described in magic(5). 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: Dv MAGIC_NONE  No special handling. Dv MAGIC_DEBUG  Print debugging messages to stderr. Dv MAGIC_SYMLINK  If the file queried is a symlink, follow it. Dv MAGIC_COMPRESS  If the file is compressed, unpack it and look at the contents. Dv MAGIC_DEVICES  If the file is a block or character special device, then open the device and try to look in its contents. Dv MAGIC_MIME_TYPE  Return a MIME type string, instead of a textual description. Dv MAGIC_MIME_ENCODING  Return a MIME encoding, instead of a textual description. Dv MAGIC_CONTINUE  Return all matches, not just the first. Dv MAGIC_CHECK  Check the magic database for consistency and print warnings to stderr. Dv MAGIC_PRESERVE_ATIME  On systems that support utime(2) or utimes(2), attempt to preserve the access time of files analyzed. Dv MAGIC_RAW  Don't translate unprintable characters to a \ooo octal representation. Dv MAGIC_ERROR  Treat operating system errors while trying to open files and follow symlinks as real errors, instead of printing them in the magic buffer. Dv MAGIC_NO_CHECK_APPTYPE  Check for  EMX application type (only on EMX). Dv MAGIC_NO_CHECK_ASCII  Check for various types of ascii files. Dv MAGIC_NO_CHECK_COMPRESS  Don't look for, or inside compressed files. Dv MAGIC_NO_CHECK_ELF  Don't print elf details. Dv MAGIC_NO_CHECK_FORTRAN  Don't look for fortran sequences inside ascii files. Dv MAGIC_NO_CHECK_SOFT  Don't consult magic files. Dv MAGIC_NO_CHECK_TAR  Don't examine tar files. Dv MAGIC_NO_CHECK_TOKENS  Don't look for known tokens inside ascii files. Dv MAGIC_NO_CHECK_TROFF  Don't look for troff sequences inside ascii files. The  magic_close() function closes the magic(5) 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/share/misc/magic.  magic_load() adds  ‟.mgc” to the database filename as appropriate. 
RETURN VALUESThe function  magic_open() 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. 
FILES   /usr/share/misc/magic   The non-compiled default magic database.    /usr/share/misc/magic.mgc   The compiled default magic database. 
SEE ALSOfile(1), magic(5) 
AUTHORSMåns Rullgård Initial libmagic implementation, and configuration. Christos Zoulas API cleanup, error code and allocation handling.  0  
   Johanes Gumabo   
 Data Size    :    19,626 byte 
man-libmagic.3Build    :     2025-03-22, 13:26     :     
Visitor Screen    :      x   
Visitor Counter  (  page  /  site  )     :     53  /  4,053,080  
Visitor ID    :        :     
Visitor IP    :     216.73.216.159     :     
Visitor Provider    :     AMAZON-02     :     
Provider Position  (  lat  x  lon  )     :     39.962500   x   -83.006100     :      x   
Provider Accuracy Radius  (  km  )     :     20     :     
Provider City    :     Columbus     :     
Provider Province    :     Ohio  ,     :     ,  
Provider Country    :     United States     :     
Provider Continent    :     North America     :     
Visitor Recorder    :    Version    :     
Visitor Recorder    :    Library    :     
Online Linux Manual Page    :    Version    :     Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 25.03.22  
Online Linux Manual Page    :    Library    :     lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40  
Online Linux Manual Page    :    Library    :     lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40  
Data Base    :    Version    :     Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38  
Data Base    :    Library    :     lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36  
  
 
    
  If error, please print screen and send to johanes_gumabo@yahoo.co.id
 Under development. Support me via PayPal.  
 ERROR : Need New Coding :          (mdoc_err|80|libmagic.3|80|Dv|.It Dv MAGIC_NONE
)          (mdoc_err|80|libmagic.3|82|Dv|.It Dv MAGIC_DEBUG
)          (mdoc_err|80|libmagic.3|84|Dv|.It Dv MAGIC_SYMLINK
)          (mdoc_err|80|libmagic.3|86|Dv|.It Dv MAGIC_COMPRESS
)          (mdoc_err|80|libmagic.3|88|Dv|.It Dv MAGIC_DEVICES
)          (mdoc_err|80|libmagic.3|91|Dv|.It Dv MAGIC_MIME_TYPE
)          (mdoc_err|80|libmagic.3|93|Dv|.It Dv MAGIC_MIME_ENCODING
)          (mdoc_err|80|libmagic.3|95|Dv|.It Dv MAGIC_CONTINUE
)          (mdoc_err|80|libmagic.3|97|Dv|.It Dv MAGIC_CHECK
)          (mdoc_err|80|libmagic.3|99|Dv|.It Dv MAGIC_PRESERVE_ATIME
)          (mdoc_err|80|libmagic.3|105|Dv|.It Dv MAGIC_RAW
)          (mdoc_err|80|libmagic.3|107|Dv|.It Dv MAGIC_ERROR
)          (mdoc_err|80|libmagic.3|110|Dv|.It Dv MAGIC_NO_CHECK_APPTYPE
)          (mdoc_err|80|libmagic.3|114|Dv|.It Dv MAGIC_NO_CHECK_ASCII
)          (mdoc_err|80|libmagic.3|116|Dv|.It Dv MAGIC_NO_CHECK_COMPRESS
)          (mdoc_err|80|libmagic.3|118|Dv|.It Dv MAGIC_NO_CHECK_ELF
)          (mdoc_err|80|libmagic.3|120|Dv|.It Dv MAGIC_NO_CHECK_FORTRAN
)          (mdoc_err|80|libmagic.3|122|Dv|.It Dv MAGIC_NO_CHECK_SOFT
)          (mdoc_err|80|libmagic.3|124|Dv|.It Dv MAGIC_NO_CHECK_TAR
)          (mdoc_err|80|libmagic.3|126|Dv|.It Dv MAGIC_NO_CHECK_TOKENS
)          (mdoc_err|80|libmagic.3|128|Dv|.It Dv MAGIC_NO_CHECK_TROFF
)