43FILE_RCSID(
"@(#)$File: is_tar.c,v 1.50 2022/12/26 17:31:14 christos Exp $")
51#define isodigit(c) ( ((c) >= '0') && ((c) <= '7') )
56static const char tartype[][32] = {
59 "POSIX tar archive (GNU)",
65 const unsigned char *
buf =
CAST(
const unsigned char *, b->
fbuf);
66 size_t nbytes = b->
flen;
78 if (tar < 1 || tar > 3)
84 if (
file_printf(ms,
"%s", mime ?
"application/x-tar" :
85 tartype[tar - 1]) == -1)
101 static const char gpkg_match[] =
"/gpkg-1";
107 const unsigned char *
p, *ep;
110 if (nbytes <
sizeof(*
header))
116 nulp =
CAST(
const char *,
117 memchr(
header->header.name, 0,
sizeof(
header->header.name)));
118 if (nulp !=
NULL && nulp >=
header->header.name +
sizeof(gpkg_match) &&
119 memcmp(nulp -
sizeof(gpkg_match) + 1, gpkg_match,
120 sizeof(gpkg_match)) == 0)
127 ep =
header->charptr +
sizeof(*header);
132 for (i = 0; i <
sizeof(
header->header.chksum); i++)
133 sum -=
header->header.chksum[i];
134 sum +=
' ' *
sizeof(
header->header.chksum);
140 sizeof(
header->header.magic)) == 0)
144 sizeof(
header->header.magic)) == 0)
164 while (isspace(
CAST(
unsigned char, *where))) {
170 while (digs > 0 &&
isodigit(*where)) {
175 if (digs > 0 && *where && !isspace(
CAST(
unsigned char, *where)))
header(string $header, bool $replace=true, int $response_code=0)
zend_ffi_ctype_name_buf buf
file_protected int file_printf(struct magic_set *, const char *,...) __attribute__((__format__(__printf__
file_private int is_tar(const unsigned char *, size_t)
file_private int from_oct(const char *, size_t)
file_protected int file_is_tar(struct magic_set *ms, const struct buffer *b)
#define MAGIC_MIME_ENCODING
strncmp(string $string1, string $string2, int $length)