libmagic

NAME

LIBRARY

SYNOPSIS

n magic.h

DESCRIPTION

These functions operate on the magic database file which is described in magic(5)
The function creates a magic cookie pointer and returns it. It returns NULL if there was an error allocating the magic cookie. The 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 contents.
  • MAGIC_DEVICES If the file is a block or character special device, then open the device and try to look in its contents.
  • MAGIC_MIME Return a mime string, instead of a textual description.
  • MAGIC_CONTINUE Return all matches, not just the first.
  • MAGIC_CHECK Check the magic database for consistency and print warnings to stderr.
  • MAGIC_PRESERVE_ATIME 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 representation.
  • 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.
  • MAGIC_NO_CHECK_APPTYPE Check for application type (only on EMX).
  • MAGIC_NO_CHECK_ASCII Check for various types of ascii files.
  • MAGIC_NO_CHECK_COMPRESS Don't look for, or inside compressed files.
  • MAGIC_NO_CHECK_ELF Don't print elf details.
  • MAGIC_NO_CHECK_FORTRAN Don't look for fortran sequences inside ascii files.
  • MAGIC_NO_CHECK_SOFT Don't consult magic files.
  • MAGIC_NO_CHECK_TAR Don't examine tar files.
  • MAGIC_NO_CHECK_TOKENS Don't look for known tokens inside ascii files.
  • MAGIC_NO_CHECK_TROFF Don't look for troff sequences inside ascii files.
The function closes the magic(5) database and deallocates any resources used.
The function returns a textual explanation of the last error, or NULL if there was no error.
The function returns the last operating system error number
that was encountered by a system call.
The function returns a textual description of the contents of the argument, or NULL if an error occurred. If the is NULL, then stdin is used.
The function returns a textual description of the contents of the argument with bytes size.
The function, sets the described above.
The function can be used to check the validity of entries in the colon separated database files passed in as or NULL for the default database. It returns 0 on success and -1 on failure.
The function can be used to compile the the colon separated list of database files passed in as 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 function must be used to load the the colon separated list of database files passed in as 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/file/magic.
adds ".mime" and/or ".mgc" to the database filename as appropriate.

RETURN VALUES

The function 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 and functions return 0 on success and -1 on failure. The and functions return a string on success and NULL on failure. The function returns a textual description of the errors of the above functions, or NULL if there was no error. Finally, returns -1 on systems that don't support utime(2) or utimes(2) when is set.

FILES

  • /usr/share/file/magic.mime The non-compiled default magic mime database.
  • /usr/share/file/magic.mime.mgc The compiled default magic mime database.
  • /usr/share/file/magic The non-compiled default magic database.
  • /usr/share/file/magic.mgc The compiled default magic database.

SEE ALSO

file(1) magic(5)

AUTHORS

M