LIBMAGIC(3) | Library Functions Manual | LIBMAGIC(3) |
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_descriptor(magic_t cookie, int fd);
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_list(magic_t cookie, const char *filename);
int
magic_load(magic_t cookie, const char *filename);
int
magic_version(void);
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:
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_descriptor() function returns a textual description of the contents of the fd argument, or NULL if an error occurred.
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_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 filename argument which is a colon separated list of database files, or NULL for the default database.
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 magic_version() command returns the version number of this library which is compiled into the shared library using the constant MAGIC_VERSION from <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.
January 6, 2012 | NetBSD 7.2 |