Seth Woolley's Man Viewer

libmagic(3) - magic_buffer, magic_check, magic_close, magic_compile, magic_error, magic_file, magic_load, magic_open, magic_setflags - Magic number recognition library - man 3 libmagic

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

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

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

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

DESCRIPTION
     These functions operate on the magic(4,5) database file(1,n) which is described in(1,8)
     magic(4,5)(4).

     The function magic_open() creates a magic(4,5) cookie pointer and returns it.
     It returns NULL if(3,n) there was an error(8,n) allocating the magic(4,5) cookie. The
     flags argument specifies how the other magic(4,5) functions should behave:

     MAGIC_NONE      No special handling.

     MAGIC_DEBUG     Print debugging messages to stderr.

     MAGIC_SYMLINK   If the file(1,n) queried is a symlink, follow it.

     MAGIC_COMPRESS  If the file(1,n) is compressed, unpack it and look(1,8,3 Search::Dict) at the con-
                     tents.

     MAGIC_DEVICES   If the file(1,n) is a block or character special device, then
                     open(2,3,n) the device and try to look(1,8,3 Search::Dict) in(1,8) its contents.

     MAGIC_MIME      Return a mime string(3,n), instead of a textual description.

     MAGIC_CONTINUE  Return all matches, not just the first.

     MAGIC_CHECK     Check the magic(4,5) database for consistency and print warn-
                     ings to stderr.

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

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

     MAGIC_ERROR     Treat operating system errors while trying to open(2,3,n) files
                     and follow symlinks as real errors, instead of printing
                     them in(1,8) the magic(4,5) buffer.

     The magic_close() function closes the magic(4,5)(4) database and deallocates
     any resources used.

     The magic_error() function returns a textual explanation of the last
     error(8,n), or NULL if(3,n) there was no error.

     The magic_errno() function returns the last operating system error(8,n) number
     ( errno(3)) 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(3,n) an error(8,n) 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.

     The magic_check() function can be used to check the validity of entries
     in(1,8) the colon separated database files passed in(1,8) 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(1,8) as filename, or NULL for the
     default database. It returns 0 on success and -1 on failure. The compiled
     files created are named(5,8) from the basename(1,3,3 File::Basename)(1) of each file(1,n) argument with
     ".mgc" appended to it.

     The magic_load() function must be used to load(7,n) the the colon separated
     list of database files passed in(1,8) as filename, or NULL for the default
     database file(1,n) before any magic(4,5) queries can performed.

     The default database file(1,n) is named(5,8) by the MAGIC environment variable.  If
     that variable is not set(7,n,1 builtins), the default database file(1,n) name is
     /usr/share/misc/file(1,n)/magic.

     magic_load() adds ".mime" and/or ".mgc" to the database filename as
     appropriate.

RETURN VALUES
     The function magic_open() returns a magic(4,5) cookie on success and NULL on
     failure setting errno to an appropriate value. It will set(7,n,1 builtins) errno to EIN-
     VAL if(3,n) 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(3,n) on success and NULL on failure. The magic_error() function returns
     a textual description of the errors of the above functions, or NULL if(3,n)
     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/file(1,n)/magic.mime      The non-compiled default magic(4,5) mime
                                          database.
     /usr/share/misc/file(1,n)/magic.mime.mgc  The compiled default magic(4,5) mime
                                          database.
     /usr/share/misc/file(1,n)/magic(4,5)           The non-compiled default magic(4,5) data-
                                          base.
     /usr/share/misc/file(1,n)/magic.mgc       The compiled default magic(4,5) database.

SEE ALSO
     file(1,n)(1), magic(4,5)(4)

AUTHORS
     Mns Rullgrd Initial libmagic implementation, and configuration.  Chris-
     tos Zoulas API cleanup, error(8,n) code and allocation handling.

BSD                             March 22, 2003                             BSD

References for this manual (incoming links)