libmagic man page on FreeBSD

Man page or keyword search:  
man Server   9747 pages
apropos Keyword Search (all sections)
Output format
FreeBSD logo
[printable version]

MAGIC(3)		 BSD Library Functions Manual		      MAGIC(3)

     magic_open, magic_close, magic_error, magic_file, magic_buffer,
     magic_setflags, magic_check, magic_compile, magic_load — Magic number
     recognition library.

     Magic Number Recognition Library (libmagic, -lmagic)

     #include <magic.h>

     magic_open(int flags);

     magic_close(magic_t cookie);

     const char *
     magic_error(magic_t cookie);

     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);

     magic_setflags(magic_t cookie, int flags);

     magic_check(magic_t cookie, const char *filename);

     magic_compile(magic_t cookie, const char *filename);

     magic_load(magic_t cookie, const char *filename);

     These functions operate on the magic database file which is described in

     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	     No special handling.

     MAGIC_DEBUG     Print debugging messages to stderr.

     MAGIC_SYMLINK   If the file queried is a symlink, follow it.

     MAGIC_COMPRESS  If the file is compressed, unpack it and look at the con‐

     MAGIC_DEVICES   If the file is a block or character special device, then
		     open the device and try to look in its contents.

		     Return a MIME type string, instead of a textual descrip‐

		     Return a MIME encoding, instead of a textual description.

     MAGIC_CONTINUE  Return all matches, not just the first.

     MAGIC_CHECK     Check the magic database for consistency and print warn‐
		     ings to stderr.

		     On systems that support utime(2) or utimes(2), attempt to
		     preserve the access time of files analyzed.

     MAGIC_RAW	     Don't translate unprintable characters to a \ooo octal

     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.

		     Check for EMX application type (only on EMX).

		     Check for various types of ascii files.

		     Don't look for, or inside compressed files.

		     Don't print elf details.

		     Don't look for fortran sequences inside ascii files.

		     Don't consult magic files.

		     Don't examine tar files.

		     Don't look for known tokens inside ascii files.

		     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

     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 sepa‐
     rated 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.

     The function magic_open() returns a magic cookie on success and NULL on
     failure setting errno to an appropriate value. It will set errno to EIN‐
     VAL 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/share/misc/magic	The non-compiled default magic database.
     /usr/share/misc/magic.mgc	The compiled default magic database.

     file(1), magic(5)

     M�ns Rullg�rd Initial libmagic implementation, and configuration.	Chris‐
     tos Zoulas API cleanup, error code and allocation handling.

BSD				October 6, 2008				   BSD

List of man pages available for FreeBSD

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
Vote for polarhome
Free Shell Accounts :: the biggest list on the net