The function Fn 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:
The Fn magic_close function closes the magic(5) database and deallocates any resources used.
The Fn magic_error function returns a textual explanation of the last error, or NULL if there was no error.
The Fn magic_errno function returns the last operating system error number (errno(2) ) that was encountered by a system call.
The Fn 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 Fn magic_descriptor function returns a textual description of the contents of the fd argument, or NULL if an error occurred.
The Fn magic_buffer function returns a textual description of the contents of the buffer argument with length bytes size.
The Fn magic_setflags function sets the flags described above. Note that using both MIME flags together can also return extra information on the charset.
The Fn 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 Fn 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 Fn magic_list function dumps all magic entries in a human readable format, dumping first the entries that are matched against binary files and then the ones that match text files. It takes and optional Fa filename argument which is a colon separated list of database files, or NULL for the default database.
The Fn 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. Fn magic_load adds ``.mgc'' to the database filename as appropriate.
The Fn magic_load_buffers function takes an array of size Fa nbuffers of Fa buffers with a respective size for each in the array of Fa sizes loaded with the contents of the magic databases from the filesystem. This function can be used in environment where the magic library does not have direct access to the filesystem, but can access the magic database via shared memory or other IPC means.
The Fn magic_getparam and Fn magic_setparam allow getting and setting various limits related to the the magic library.
The MAGIC_PARAM_INDIR_RECURSION parameter controls how many levels of recursion will be followed for indirect magic entries.
The MAGIC_PARAM_NAME_RECURSION parameter controls how many levels of recursion will be followed for for name/use calls.
The MAGIC_PARAM_NAME_MAX parameter controls the maximum number of calls for name/use.
The MAGIC_PARAM_NOTES_MAX parameter controls how many ELF notes will be processed.
The MAGIC_PARAM_PHNUM_MAX parameter controls how many ELF program sections will be processed.
The MAGIC_PARAM_SHNUM_MAX parameter controls how many ELF sections will be processed.
The Fn magic_version command returns the version number of this library which is compiled into the shared library using the constant MAGIC_VERSION from In magic.h . This can be used by client programs to verify that the version they compile against is the same as the version that they run against.