Sortix cross-nightly manual
This manual documents Sortix cross-nightly. You can instead view this document in the latest official manual.
NAME
magic_open, magic_close, magic_error, magic_errno, magic_descriptor, magic_buffer, magic_getflags, magic_setflags, magic_check, magic_compile, magic_list, magic_load, magic_load_buffers, magic_setparam, magic_getparam, magic_version — Magic number recognition libraryLIBRARY
Magic Number Recognition Library (libmagic, -lmagic)SYNOPSIS
#include <magic.h>magic_open(int flags);
magic_close(magic_t cookie);
magic_error(magic_t cookie);
magic_errno(magic_t cookie);
magic_descriptor(magic_t cookie, int fd);
magic_file(magic_t cookie, const char *filename);
magic_buffer(magic_t cookie, const void *buffer, size_t length);
magic_getflags(magic_t cookie);
magic_setflags(magic_t cookie, int flags);
magic_check(magic_t cookie, const char *filename);
magic_compile(magic_t cookie, const char *filename);
magic_list(magic_t cookie, const char *filename);
magic_load(magic_t cookie, const char *filename);
magic_load_buffers(magic_t cookie, void **buffers, size_t *sizes, size_t nbuffers);
magic_getparam(magic_t cookie, int param, void *value);
magic_setparam(magic_t cookie, int param, const void *value);
magic_version(void);
magic_getpath(const char *magicfile, int action);
DESCRIPTION
These functions operate on the magic database file which is described in magic(5).- 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_TYPE
- Return a MIME type string, instead of a textual description.
- MAGIC_MIME_ENCODING
- Return a MIME encoding, instead of a textual description.
- MAGIC_MIME
- A shorthand for MAGIC_MIME_TYPE | MAGIC_MIME_ENCODING.
- 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(3) or utimes(2), attempt to preserve the access time of files analysed.
- 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_APPLE
- Return the Apple creator and type.
- MAGIC_EXTENSION
- Return a slash-separated list of extensions for this file type.
- MAGIC_COMPRESS_TRANSP
- Don't report on compression, only report about the uncompressed data.
- MAGIC_NO_CHECK_APPTYPE
- Don't check for EMX application type (only on EMX).
- MAGIC_NO_COMPRESS_FORK
- Don't allow decompressors that use fork.
- MAGIC_NO_CHECK_CDF
- Don't get extra information on MS Composite Document Files.
- MAGIC_NO_CHECK_COMPRESS
- Don't look inside compressed files.
- MAGIC_NO_CHECK_ELF
- Don't print ELF details.
- MAGIC_NO_CHECK_ENCODING
- Don't check text encodings.
- MAGIC_NO_CHECK_SOFT
- Don't consult magic files.
- MAGIC_NO_CHECK_TAR
- Don't examine tar files.
- MAGIC_NO_CHECK_TEXT
- Don't check for various types of text files.
- MAGIC_NO_CHECK_TOKENS
- Don't look for known tokens inside ascii files.
- MAGIC_NO_CHECK_JSON
- Don't examine JSON files.
- MAGIC_NO_CHECK_CSV
- Don't examine CSV files.
- MAGIC_NO_CHECK_SIMH
- Don't examine SIMH tape files.
| Parameter | Type | Default |
MAGIC_PARAM_INDIR_MAX |
size_t | 15 |
MAGIC_PARAM_NAME_MAX |
size_t | 30 |
MAGIC_PARAM_ELF_NOTES_MAX |
size_t | 256 |
MAGIC_PARAM_ELF_PHNUM_MAX |
size_t | 128 |
MAGIC_PARAM_ELF_SHNUM_MAX |
size_t | 32768 |
MAGIC_PARAM_REGEX_MAX |
size_t | 8192 |
MAGIC_PARAM_BYTES_MAX |
size_t | 7340032 |
MAGIC_PARAM_ENCODING_MAX |
size_t | 1048576 |
MAGIC_PARAM_ELF_SHSIZE_MAX |
size_t | 134217728 |
MAGIC_PARAM_MAGWARN_MAX |
size_t | 64 |
RETURN VALUES
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 EINVAL if an unsupported value for flags was given. The magic_list(), magic_load(), magic_compile(), and magic_check() functions return 0 on success and -1 on failure. The magic_buffer(), magic_getpath(), and magic_file(), 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. The magic_version() always returns the version number of the library. Finally, magic_setflags() returns -1 on systems that don't support utime(3), or utimes(2) when MAGIC_PRESERVE_ATIME is set.FILES
- /share/misc/magic
- The non-compiled default magic database.
- /share/misc/magic.mgc
- The compiled default magic database.
BUGS
The results from magic_buffer() and magic_file() where the buffer and the file contain the same data can produce different results, because in the magic_file() case, the program can lseek(2) and stat(2) the file descriptor.AUTHORS
Initial libmagic implementation, and configuration.API cleanup, error code and allocation handling.