{
    "content": [
        {
            "type": "text",
            "text": "# libmagic (man)\n\n## NAME\n\nmagicopen, magicclose, magicerror, magicerrno, magicdescriptor, magicbuffer, magicgetflags, magicsetflags, magiccheck, magiccompile, magiclist, magicload, magicloadbuffers, magicsetparam, magicgetparam, magicversion — Magic number recognition library\n\n## DESCRIPTION\n\nThese functions operate on the magic database file which is described in magic(5).\n\n## Sections\n\n- **NAME**\n- **LIBRARY**\n- **SYNOPSIS** (1 subsections)\n- **DESCRIPTION**\n- **RETURN VALUES**\n- **FILES**\n- **SEE ALSO**\n- **BUGS**\n- **AUTHORS**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "libmagic",
        "section": "",
        "mode": "man",
        "summary": "magicopen, magicclose, magicerror, magicerrno, magicdescriptor, magicbuffer, magicgetflags, magicsetflags, magiccheck, magiccompile, magiclist, magicload, magicloadbuffers, magicsetparam, magicgetparam, magicversion — Magic number recognition library",
        "synopsis": "",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "file",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/file/1/json"
            },
            {
                "name": "magic",
                "section": "5",
                "url": "https://www.chedong.com/phpMan.php/man/magic/5/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "LIBRARY",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "#include <magic.h>",
                        "lines": 51
                    }
                ]
            },
            {
                "name": "DESCRIPTION",
                "lines": 160,
                "subsections": []
            },
            {
                "name": "RETURN VALUES",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "FILES",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "AUTHORS",
                "lines": 4,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "magicopen, magicclose, magicerror, magicerrno, magicdescriptor, magicbuffer,\nmagicgetflags, magicsetflags, magiccheck, magiccompile, magiclist, magicload,\nmagicloadbuffers, magicsetparam, magicgetparam, magicversion — Magic number recognition\nlibrary\n",
                "subsections": []
            },
            "LIBRARY": {
                "content": "Magic Number Recognition Library (libmagic, -lmagic)\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "",
                "subsections": [
                    {
                        "name": "#include <magic.h>",
                        "content": "magict\nmagicopen(int flags);\n\nvoid\nmagicclose(magict cookie);\n\nconst char *\nmagicerror(magict cookie);\n\nint\nmagicerrno(magict cookie);\n\nconst char *\nmagicdescriptor(magict cookie, int fd);\n\nconst char *\nmagicfile(magict cookie, const char *filename);\n\nconst char *\nmagicbuffer(magict cookie, const void *buffer, sizet length);\n\nint\nmagicgetflags(magict cookie);\n\nint\nmagicsetflags(magict cookie, int flags);\n\nint\nmagiccheck(magict cookie, const char *filename);\n\nint\nmagiccompile(magict cookie, const char *filename);\n\nint\nmagiclist(magict cookie, const char *filename);\n\nint\nmagicload(magict cookie, const char *filename);\n\nint\nmagicloadbuffers(magict cookie, void buffers, sizet *sizes, sizet nbuffers);\n\nint\nmagicgetparam(magict cookie, int param, void *value);\n\nint\nmagicsetparam(magict cookie, int param, const void *value);\n\nint\nmagicversion(void);\n"
                    }
                ]
            },
            "DESCRIPTION": {
                "content": "These functions operate on the magic database file which is described in magic(5).\n\nThe function magicopen() creates a magic cookie pointer and returns it.  It returns NULL if\nthere was an error allocating the magic cookie.  The flags argument specifies how the other\nmagic functions should behave:\n\nMAGICNONE      No special handling.\n\nMAGICDEBUG     Print debugging messages to stderr.\n\nMAGICSYMLINK   If the file queried is a symlink, follow it.\n\nMAGICCOMPRESS  If the file is compressed, unpack it and look at the contents.\n\nMAGICDEVICES   If the file is a block or character special device, then open the device and\ntry to look in its contents.\n\nMAGICMIMETYPE\nReturn a MIME type string, instead of a textual description.\n\nMAGICMIMEENCODING\nReturn a MIME encoding, instead of a textual description.\n\nMAGICMIME      A shorthand for MAGICMIMETYPE | MAGICMIMEENCODING.\n\nMAGICCONTINUE  Return all matches, not just the first.\n\nMAGICCHECK     Check the magic database for consistency and print warnings to stderr.\n\nMAGICPRESERVEATIME\nOn systems that support utime(3) or utimes(2), attempt to preserve the access\ntime of files analysed.\n\nMAGICRAW       Don't translate unprintable characters to a \\ooo octal representation.\n\nMAGICERROR     Treat operating system errors while trying to open files and follow symlinks as\nreal errors, instead of printing them in the magic buffer.\n\nMAGICAPPLE     Return the Apple creator and type.\n\nMAGICEXTENSION\nReturn a slash-separated list of extensions for this file type.\n\nMAGICCOMPRESSTRANSP\nDon't report on compression, only report about the uncompressed data.\n\nMAGICNOCHECKAPPTYPE\nDon't check for EMX application type (only on EMX).\n\nMAGICNOCHECKCDF\nDon't get extra information on MS Composite Document Files.\n\nMAGICNOCHECKCOMPRESS\nDon't look inside compressed files.\n\nMAGICNOCHECKELF\nDon't print ELF details.\n\nMAGICNOCHECKENCODING\nDon't check text encodings.\n\nMAGICNOCHECKSOFT\nDon't consult magic files.\n\nMAGICNOCHECKTAR\nDon't examine tar files.\n\nMAGICNOCHECKTEXT\nDon't check for various types of text files.\n\nMAGICNOCHECKTOKENS\nDon't look for known tokens inside ascii files.\n\nMAGICNOCHECKJSON\nDon't examine JSON files.\n\nMAGICNOCHECKCSV\nDon't examine CSV files.\n\nThe magicclose() function closes the magic(5) database and deallocates any resources used.\n\nThe magicerror() function returns a textual explanation of the last error, or NULL if there\nwas no error.\n\nThe magicerrno() function returns the last operating system error number (errno(2)) that was\nencountered by a system call.\n\nThe magicfile() function returns a textual description of the contents of the filename argu‐\nment, or NULL if an error occurred.  If the filename is NULL, then stdin is used.\n\nThe magicdescriptor() function returns a textual description of the contents of the fd argu‐\nment, or NULL if an error occurred.\n\nThe magicbuffer() function returns a textual description of the contents of the buffer argu‐\nment with length bytes size.\n\nThe magicgetflags() functions returns a value representing current flags set.\n\nThe magicsetflags() function sets the flags described above.  Note that using both MIME flags\ntogether can also return extra information on the charset.\n\nThe magiccheck() function can be used to check the validity of entries in the colon separated\ndatabase files passed in as filename, or NULL for the default database.  It returns 0 on suc‐\ncess and -1 on failure.\n\nThe magiccompile() function can be used to compile the colon separated list of database files\npassed in as filename, or NULL for the default database.  It returns 0 on success and -1 on\nfailure.  The compiled files created are named from the basename(1) of each file argument with\n“.mgc” appended to it.\n\nThe magiclist() function dumps all magic entries in a human readable format, dumping first the\nentries that are matched against binary files and then the ones that match text files.  It\ntakes and optional filename argument which is a colon separated list of database files, or NULL\nfor the default database.\n\nThe magicload() function must be used to load the colon separated list of database files\npassed in as filename, or NULL for the default database file before any magic queries can per‐\nformed.\n\nThe default database file is named by the MAGIC environment variable.  If that variable is not\nset, the default database file name is /usr/share/misc/magic.  magicload() adds “.mgc” to the\ndatabase filename as appropriate.\n\nThe magicloadbuffers() function takes an array of size nbuffers of buffers with a respective\nsize for each in the array of sizes loaded with the contents of the magic databases from the\nfilesystem.  This function can be used in environment where the magic library does not have di‐\nrect access to the filesystem, but can access the magic database via shared memory or other IPC\nmeans.\n\nThe magicgetparam() and magicsetparam() allow getting and setting various limits related to\nthe magic library.\n\nParameter                    Type      Default\nMAGICPARAMINDIRMAX        sizet    15\nMAGICPARAMNAMEMAX         sizet    30\nMAGICPARAMELFNOTESMAX    sizet    256\nMAGICPARAMELFPHNUMMAX    sizet    128\nMAGICPARAMELFSHNUMMAX    sizet    32768\nMAGICPARAMREGEXMAX        sizet    8192\nMAGICPARAMBYTESMAX        sizet    1048576\n\nThe MAGICPARAMINDIRRECURSION parameter controls how many levels of recursion will be fol‐\nlowed for indirect magic entries.\n\nThe MAGICPARAMNAMERECURSION parameter controls how many levels of recursion will be followed\nfor for name/use calls.\n\nThe MAGICPARAMNAMEMAX parameter controls the maximum number of calls for name/use.\n\nThe MAGICPARAMNOTESMAX parameter controls how many ELF notes will be processed.\n\nThe MAGICPARAMPHNUMMAX parameter controls how many ELF program sections will be processed.\n\nThe MAGICPARAMSHNUMMAX parameter controls how many ELF sections will be processed.\n\nThe magicversion() command returns the version number of this library which is compiled into\nthe shared library using the constant MAGICVERSION from <magic.h>.  This can be used by client\nprograms to verify that the version they compile against is the same as the version that they\nrun against.\n",
                "subsections": []
            },
            "RETURN VALUES": {
                "content": "The function magicopen() returns a magic cookie on success and NULL on failure setting errno\nto an appropriate value.  It will set errno to EINVAL if an unsupported value for flags was\ngiven.  The magiclist(), magicload(), magiccompile(), and magiccheck() functions return 0\non success and -1 on failure.  The magicbuffer(), magicgetpath(), and magicfile(), functions\nreturn a string on success and NULL on failure.  The magicerror() function returns a textual\ndescription of the errors of the above functions, or NULL if there was no error.  The\nmagicversion() always returns the version number of the library.  Finally, magicsetflags()\nreturns -1 on systems that don't support utime(3), or utimes(2) when MAGICPRESERVEATIME is\nset.\n",
                "subsections": []
            },
            "FILES": {
                "content": "/usr/share/misc/magic      The non-compiled default magic database.\n/usr/share/misc/magic.mgc  The compiled default magic database.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "file(1), magic(5)\n",
                "subsections": []
            },
            "BUGS": {
                "content": "The results from magicbuffer() and magicfile() where the buffer and the file contain the same\ndata can produce different results, because in the magicfile() case, the program can lseek(2)\nand stat(2) the file descriptor.\n",
                "subsections": []
            },
            "AUTHORS": {
                "content": "Måns Rullgård Initial libmagic implementation, and configuration.\nChristos Zoulas API cleanup, error code and allocation handling.\n\nBSD                              June 8, 2019                              BSD",
                "subsections": []
            }
        }
    }
}