Reducing external/bsd/file differences
Change-Id: I0d025059ba0b200ac1162ea5a764fd756600ecd0
This commit is contained in:
2
external/bsd/file/dist/src/Makefile.am
vendored
2
external/bsd/file/dist/src/Makefile.am
vendored
@@ -9,7 +9,7 @@ AM_CFLAGS = @WARNINGS@
|
||||
|
||||
libmagic_la_SOURCES = magic.c apprentice.c softmagic.c ascmagic.c \
|
||||
encoding.c compress.c is_tar.c readelf.c print.c fsmagic.c \
|
||||
funcs.c file.h names.h readelf.h tar.h apptype.c \
|
||||
funcs.c file.h readelf.h tar.h apptype.c \
|
||||
file_opts.h elfclass.h mygetopt.h cdf.c cdf_time.c readcdf.c cdf.h
|
||||
libmagic_la_LDFLAGS = -no-undefined -version-info 1:0:0
|
||||
if MINGW
|
||||
|
||||
2
external/bsd/file/dist/src/Makefile.in
vendored
2
external/bsd/file/dist/src/Makefile.in
vendored
@@ -248,7 +248,7 @@ AM_CPPFLAGS = -DMAGIC='"$(MAGIC)"'
|
||||
AM_CFLAGS = @WARNINGS@
|
||||
libmagic_la_SOURCES = magic.c apprentice.c softmagic.c ascmagic.c \
|
||||
encoding.c compress.c is_tar.c readelf.c print.c fsmagic.c \
|
||||
funcs.c file.h names.h readelf.h tar.h apptype.c \
|
||||
funcs.c file.h readelf.h tar.h apptype.c \
|
||||
file_opts.h elfclass.h mygetopt.h cdf.c cdf_time.c readcdf.c cdf.h
|
||||
|
||||
libmagic_la_LDFLAGS = -no-undefined -version-info 1:0:0
|
||||
|
||||
21
external/bsd/file/dist/src/apprentice.c
vendored
21
external/bsd/file/dist/src/apprentice.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: apprentice.c,v 1.5 2011/09/16 21:06:26 christos Exp $ */
|
||||
/* $NetBSD: apprentice.c,v 1.7 2012/04/07 17:30:55 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
@@ -35,9 +35,9 @@
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
FILE_RCSID("@(#)$File: apprentice.c,v 1.170 2011/06/10 09:23:28 christos Exp $")
|
||||
FILE_RCSID("@(#)$File: apprentice.c,v 1.173 2011/12/08 12:38:24 rrt Exp $")
|
||||
#else
|
||||
__RCSID("$NetBSD: apprentice.c,v 1.5 2011/09/16 21:06:26 christos Exp $");
|
||||
__RCSID("$NetBSD: apprentice.c,v 1.7 2012/04/07 17:30:55 christos Exp $");
|
||||
#endif
|
||||
#endif /* lint */
|
||||
|
||||
@@ -218,7 +218,7 @@ static const struct type_tbl_s {
|
||||
{ XX("ledouble"), FILE_LEDOUBLE, FILE_FMT_DOUBLE },
|
||||
{ XX("leid3"), FILE_LEID3, FILE_FMT_NUM },
|
||||
{ XX("beid3"), FILE_BEID3, FILE_FMT_NUM },
|
||||
{ XX("indirect"), FILE_INDIRECT, FILE_FMT_NONE },
|
||||
{ XX("indirect"), FILE_INDIRECT, FILE_FMT_NUM },
|
||||
{ XX_NULL, FILE_INVALID, FILE_FMT_NONE },
|
||||
# undef XX
|
||||
# undef XX_NULL
|
||||
@@ -477,6 +477,9 @@ apprentice_magic_strength(const struct magic *m)
|
||||
val += 8 * MULT;
|
||||
break;
|
||||
|
||||
case FILE_INDIRECT:
|
||||
break;
|
||||
|
||||
default:
|
||||
val = 0;
|
||||
(void)fprintf(stderr, "Bad type %d\n", m->type);
|
||||
@@ -742,8 +745,7 @@ load_1(struct magic_set *ms, int action, const char *fn, int *errs,
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (line)
|
||||
free(line);
|
||||
free(line);
|
||||
(void)fclose(f);
|
||||
}
|
||||
|
||||
@@ -796,6 +798,7 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
|
||||
file_oomem(ms,
|
||||
strlen(fn) + strlen(d->d_name) + 2);
|
||||
errs++;
|
||||
closedir(dir);
|
||||
goto out;
|
||||
}
|
||||
if (stat(mfn, &st) == -1 || !S_ISREG(st.st_mode)) {
|
||||
@@ -810,6 +813,7 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
|
||||
realloc(filearr, mlen))) == NULL) {
|
||||
file_oomem(ms, mlen);
|
||||
free(mfn);
|
||||
closedir(dir);
|
||||
errs++;
|
||||
goto out;
|
||||
}
|
||||
@@ -2306,7 +2310,7 @@ private int
|
||||
apprentice_compile(struct magic_set *ms, struct magic **magicp,
|
||||
uint32_t *nmagicp, const char *fn)
|
||||
{
|
||||
int fd;
|
||||
int fd = -1;
|
||||
char *dbname;
|
||||
int rv = -1;
|
||||
|
||||
@@ -2337,7 +2341,8 @@ apprentice_compile(struct magic_set *ms, struct magic **magicp,
|
||||
goto out;
|
||||
}
|
||||
|
||||
(void)close(fd);
|
||||
if (fd != -1)
|
||||
(void)close(fd);
|
||||
rv = 0;
|
||||
out:
|
||||
free(dbname);
|
||||
|
||||
98
external/bsd/file/dist/src/ascmagic.c
vendored
98
external/bsd/file/dist/src/ascmagic.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ascmagic.c,v 1.1.1.2 2011/05/12 20:46:52 christos Exp $ */
|
||||
/* $NetBSD: ascmagic.c,v 1.1.1.3 2012/02/22 17:48:22 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
@@ -38,9 +38,9 @@
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
FILE_RCSID("@(#)$File: ascmagic.c,v 1.81 2011/03/15 22:16:29 christos Exp $")
|
||||
FILE_RCSID("@(#)$File: ascmagic.c,v 1.84 2011/12/08 12:38:24 rrt Exp $")
|
||||
#else
|
||||
__RCSID("$NetBSD: ascmagic.c,v 1.1.1.2 2011/05/12 20:46:52 christos Exp $");
|
||||
__RCSID("$NetBSD: ascmagic.c,v 1.1.1.3 2012/02/22 17:48:22 christos Exp $");
|
||||
#endif
|
||||
#endif /* lint */
|
||||
|
||||
@@ -52,13 +52,11 @@ __RCSID("$NetBSD: ascmagic.c,v 1.1.1.2 2011/05/12 20:46:52 christos Exp $");
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "names.h"
|
||||
|
||||
#define MAXLINELEN 300 /* longest sane line length */
|
||||
#define ISSPC(x) ((x) == ' ' || (x) == '\t' || (x) == '\r' || (x) == '\n' \
|
||||
|| (x) == 0x85 || (x) == '\f')
|
||||
|
||||
private int ascmatch(const unsigned char *, const unichar *, size_t);
|
||||
private unsigned char *encode_utf8(unsigned char *, size_t, unichar *, size_t);
|
||||
private size_t trim_nuls(const unsigned char *, size_t);
|
||||
|
||||
@@ -76,7 +74,8 @@ trim_nuls(const unsigned char *buf, size_t nbytes)
|
||||
}
|
||||
|
||||
protected int
|
||||
file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
|
||||
file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
|
||||
int text)
|
||||
{
|
||||
unichar *ubuf = NULL;
|
||||
size_t ulen;
|
||||
@@ -93,17 +92,13 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
|
||||
|
||||
/* If file doesn't look like any sort of text, give up. */
|
||||
if (file_encoding(ms, buf, nbytes, &ubuf, &ulen, &code, &code_mime,
|
||||
&type) == 0) {
|
||||
&type) == 0)
|
||||
rv = 0;
|
||||
goto done;
|
||||
}
|
||||
else
|
||||
rv = file_ascmagic_with_encoding(ms, buf, nbytes, ubuf, ulen, code,
|
||||
type, text);
|
||||
|
||||
rv = file_ascmagic_with_encoding(ms, buf, nbytes, ubuf, ulen, code,
|
||||
type);
|
||||
|
||||
done:
|
||||
if (ubuf)
|
||||
free(ubuf);
|
||||
free(ubuf);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -111,11 +106,10 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
|
||||
protected int
|
||||
file_ascmagic_with_encoding(struct magic_set *ms, const unsigned char *buf,
|
||||
size_t nbytes, unichar *ubuf, size_t ulen, const char *code,
|
||||
const char *type)
|
||||
const char *type, int text)
|
||||
{
|
||||
unsigned char *utf8_buf = NULL, *utf8_end;
|
||||
size_t mlen, i;
|
||||
const struct names *p;
|
||||
int rv = -1;
|
||||
int mime = ms->flags & MAGIC_MIME;
|
||||
|
||||
@@ -130,7 +124,7 @@ file_ascmagic_with_encoding(struct magic_set *ms, const unsigned char *buf,
|
||||
int n_lf = 0;
|
||||
int n_cr = 0;
|
||||
int n_nel = 0;
|
||||
int score, curtype, executable = 0;
|
||||
int executable = 0;
|
||||
|
||||
size_t last_line_end = (size_t)-1;
|
||||
int has_long_lines = 0;
|
||||
@@ -159,57 +153,10 @@ file_ascmagic_with_encoding(struct magic_set *ms, const unsigned char *buf,
|
||||
== NULL)
|
||||
goto done;
|
||||
if ((rv = file_softmagic(ms, utf8_buf,
|
||||
(size_t)(utf8_end - utf8_buf), TEXTTEST)) != 0)
|
||||
goto subtype_identified;
|
||||
else
|
||||
(size_t)(utf8_end - utf8_buf), TEXTTEST, text)) == 0)
|
||||
rv = -1;
|
||||
}
|
||||
|
||||
/* look for tokens from names.h - this is expensive! */
|
||||
if ((ms->flags & MAGIC_NO_CHECK_TOKENS) != 0)
|
||||
goto subtype_identified;
|
||||
|
||||
i = 0;
|
||||
score = 0;
|
||||
curtype = -1;
|
||||
while (i < ulen) {
|
||||
size_t end;
|
||||
|
||||
/* skip past any leading space */
|
||||
while (i < ulen && ISSPC(ubuf[i]))
|
||||
i++;
|
||||
if (i >= ulen)
|
||||
break;
|
||||
|
||||
/* find the next whitespace */
|
||||
for (end = i + 1; end < nbytes; end++)
|
||||
if (ISSPC(ubuf[end]))
|
||||
break;
|
||||
|
||||
/* compare the word thus isolated against the token list */
|
||||
for (p = names; p < names + NNAMES; p++) {
|
||||
if (ascmatch((const unsigned char *)p->name, ubuf + i,
|
||||
end - i)) {
|
||||
if (curtype == -1)
|
||||
curtype = p->type;
|
||||
else if (curtype != p->type) {
|
||||
score = p->score;
|
||||
curtype = p->type;
|
||||
} else
|
||||
score += p->score;
|
||||
if (score > 1) {
|
||||
subtype = types[p->type].human;
|
||||
subtype_mime = types[p->type].mime;
|
||||
goto subtype_identified;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i = end;
|
||||
}
|
||||
|
||||
subtype_identified:
|
||||
|
||||
/* Now try to discover other details about the file. */
|
||||
for (i = 0; i < ulen; i++) {
|
||||
if (ubuf[i] == '\n') {
|
||||
@@ -355,28 +302,11 @@ subtype_identified:
|
||||
}
|
||||
rv = 1;
|
||||
done:
|
||||
if (utf8_buf)
|
||||
free(utf8_buf);
|
||||
free(utf8_buf);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
private int
|
||||
ascmatch(const unsigned char *s, const unichar *us, size_t ulen)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < ulen; i++) {
|
||||
if (s[i] != us[i])
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (s[i])
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Encode Unicode string as UTF-8, returning pointer to character
|
||||
* after end of string, or NULL if an invalid character is found.
|
||||
|
||||
103
external/bsd/file/dist/src/cdf.c
vendored
103
external/bsd/file/dist/src/cdf.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: cdf.c,v 1.5 2011/09/16 21:06:26 christos Exp $ */
|
||||
/* $NetBSD: cdf.c,v 1.6 2012/02/22 17:53:51 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 Christos Zoulas
|
||||
@@ -38,9 +38,9 @@
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
FILE_RCSID("@(#)$File: cdf.c,v 1.45 2011/08/28 08:38:48 christos Exp $")
|
||||
FILE_RCSID("@(#)$File: cdf.c,v 1.50 2012/02/20 22:35:29 christos Exp $")
|
||||
#else
|
||||
__RCSID("$NetBSD: cdf.c,v 1.5 2011/09/16 21:06:26 christos Exp $");
|
||||
__RCSID("$NetBSD: cdf.c,v 1.6 2012/02/22 17:53:51 christos Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -63,10 +63,6 @@ __RCSID("$NetBSD: cdf.c,v 1.5 2011/09/16 21:06:26 christos Exp $");
|
||||
|
||||
#include "cdf.h"
|
||||
|
||||
#ifndef __arraycount
|
||||
#define __arraycount(a) (sizeof(a) / sizeof(a[0]))
|
||||
#endif
|
||||
|
||||
#ifdef CDF_DEBUG
|
||||
#define DPRINTF(a) printf a, fflush(stdout)
|
||||
#else
|
||||
@@ -85,6 +81,7 @@ static union {
|
||||
#define CDF_TOLE2(x) ((uint16_t)(NEED_SWAP ? _cdf_tole2(x) : (uint16_t)(x)))
|
||||
#define CDF_GETUINT32(x, y) cdf_getuint32(x, y)
|
||||
|
||||
|
||||
/*
|
||||
* swap a short
|
||||
*/
|
||||
@@ -351,18 +348,27 @@ ssize_t
|
||||
cdf_read_sector(const cdf_info_t *info, void *buf, size_t offs, size_t len,
|
||||
const cdf_header_t *h, cdf_secid_t id)
|
||||
{
|
||||
assert((size_t)CDF_SEC_SIZE(h) == len);
|
||||
return cdf_read(info, (off_t)CDF_SEC_POS(h, id),
|
||||
((char *)buf) + offs, len);
|
||||
size_t ss = CDF_SEC_SIZE(h);
|
||||
size_t pos = CDF_SEC_POS(h, id);
|
||||
assert(ss == len);
|
||||
return cdf_read(info, (off_t)pos, ((char *)buf) + offs, len);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
cdf_read_short_sector(const cdf_stream_t *sst, void *buf, size_t offs,
|
||||
size_t len, const cdf_header_t *h, cdf_secid_t id)
|
||||
{
|
||||
assert((size_t)CDF_SHORT_SEC_SIZE(h) == len);
|
||||
size_t ss = CDF_SHORT_SEC_SIZE(h);
|
||||
size_t pos = CDF_SHORT_SEC_POS(h, id);
|
||||
assert(ss == len);
|
||||
if (pos > CDF_SEC_SIZE(h) * sst->sst_len) {
|
||||
DPRINTF(("Out of bounds read %" SIZE_T_FORMAT "u > %"
|
||||
SIZE_T_FORMAT "u\n",
|
||||
pos, CDF_SEC_SIZE(h) * sst->sst_len));
|
||||
return -1;
|
||||
}
|
||||
(void)memcpy(((char *)buf) + offs,
|
||||
((const char *)sst->sst_tab) + CDF_SHORT_SEC_POS(h, id), len);
|
||||
((const char *)sst->sst_tab) + pos, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
@@ -429,8 +435,8 @@ cdf_read_sat(const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat)
|
||||
if (sec < 0)
|
||||
goto out;
|
||||
if (i >= sat->sat_len) {
|
||||
DPRINTF(("Out of bounds reading MSA %u >= %u",
|
||||
i, sat->sat_len));
|
||||
DPRINTF(("Out of bounds reading MSA %" SIZE_T_FORMAT
|
||||
"u >= %" SIZE_T_FORMAT "u", i, sat->sat_len));
|
||||
errno = EFTYPE;
|
||||
goto out2;
|
||||
}
|
||||
@@ -503,7 +509,8 @@ cdf_read_long_sector_chain(const cdf_info_t *info, const cdf_header_t *h,
|
||||
}
|
||||
if (i >= scn->sst_len) {
|
||||
DPRINTF(("Out of bounds reading long sector chain "
|
||||
"%u > %u\n", i, scn->sst_len));
|
||||
"%" SIZE_T_FORMAT "u > %" SIZE_T_FORMAT "u\n", i,
|
||||
scn->sst_len));
|
||||
errno = EFTYPE;
|
||||
goto out;
|
||||
}
|
||||
@@ -548,7 +555,8 @@ cdf_read_short_sector_chain(const cdf_header_t *h,
|
||||
}
|
||||
if (i >= scn->sst_len) {
|
||||
DPRINTF(("Out of bounds reading short sector chain "
|
||||
"%u > %u\n", i, scn->sst_len));
|
||||
"%" SIZE_T_FORMAT "u > %" SIZE_T_FORMAT "u\n",
|
||||
i, scn->sst_len));
|
||||
errno = EFTYPE;
|
||||
goto out;
|
||||
}
|
||||
@@ -656,7 +664,8 @@ cdf_read_ssat(const cdf_info_t *info, const cdf_header_t *h,
|
||||
}
|
||||
if (i >= ssat->sat_len) {
|
||||
DPRINTF(("Out of bounds reading short sector chain "
|
||||
"%u > %u\n", i, ssat->sat_len));
|
||||
"%" SIZE_T_FORMAT "u > %" SIZE_T_FORMAT "u\n", i,
|
||||
ssat->sat_len));
|
||||
errno = EFTYPE;
|
||||
goto out;
|
||||
}
|
||||
@@ -796,17 +805,18 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
|
||||
if (cdf_check_stream_offset(sst, h, e, 0, __LINE__) == -1)
|
||||
goto out;
|
||||
for (i = 0; i < sh.sh_properties; i++) {
|
||||
size_t ofs = CDF_GETUINT32(p, (i << 1) + 1);
|
||||
q = (const uint8_t *)(const void *)
|
||||
((const char *)(const void *)p +
|
||||
CDF_GETUINT32(p, (i << 1) + 1)) - 2 * sizeof(uint32_t);
|
||||
((const char *)(const void *)p + ofs
|
||||
- 2 * sizeof(uint32_t));
|
||||
if (q > e) {
|
||||
DPRINTF(("Ran of the end %p > %p\n", q, e));
|
||||
goto out;
|
||||
}
|
||||
inp[i].pi_id = CDF_GETUINT32(p, i << 1);
|
||||
inp[i].pi_type = CDF_GETUINT32(q, 0);
|
||||
DPRINTF(("%d) id=%x type=%x offs=%x,%d\n", i, inp[i].pi_id,
|
||||
inp[i].pi_type, q - p, CDF_GETUINT32(p, (i << 1) + 1)));
|
||||
DPRINTF(("%" SIZE_T_FORMAT "u) id=%x type=%x offs=0x%tx,0x%x\n",
|
||||
i, inp[i].pi_id, inp[i].pi_type, q - p, offs));
|
||||
if (inp[i].pi_type & CDF_VECTOR) {
|
||||
nelements = CDF_GETUINT32(q, 1);
|
||||
o = 2;
|
||||
@@ -852,6 +862,20 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
|
||||
(void)memcpy(&u64, &q[o4], sizeof(u64));
|
||||
inp[i].pi_u64 = CDF_TOLE8((uint64_t)u64);
|
||||
break;
|
||||
case CDF_FLOAT:
|
||||
if (inp[i].pi_type & CDF_VECTOR)
|
||||
goto unknown;
|
||||
(void)memcpy(&u32, &q[o4], sizeof(u32));
|
||||
u32 = CDF_TOLE4(u32);
|
||||
memcpy(&inp[i].pi_f, &u32, sizeof(inp[i].pi_f));
|
||||
break;
|
||||
case CDF_DOUBLE:
|
||||
if (inp[i].pi_type & CDF_VECTOR)
|
||||
goto unknown;
|
||||
(void)memcpy(&u64, &q[o4], sizeof(u64));
|
||||
u64 = CDF_TOLE8((uint64_t)u64);
|
||||
memcpy(&inp[i].pi_d, &u64, sizeof(inp[i].pi_d));
|
||||
break;
|
||||
case CDF_LENGTH32_STRING:
|
||||
case CDF_LENGTH32_WSTRING:
|
||||
if (nelements > 1) {
|
||||
@@ -867,17 +891,22 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
|
||||
*info = inp;
|
||||
inp = *info + nelem;
|
||||
}
|
||||
DPRINTF(("nelements = %d\n", nelements));
|
||||
DPRINTF(("nelements = %" SIZE_T_FORMAT "u\n",
|
||||
nelements));
|
||||
for (j = 0; j < nelements; j++, i++) {
|
||||
uint32_t l = CDF_GETUINT32(q, o);
|
||||
inp[i].pi_str.s_len = l;
|
||||
inp[i].pi_str.s_buf = (const char *)
|
||||
(const void *)(&q[o4 + sizeof(l)]);
|
||||
DPRINTF(("l = %d, r = %d, s = %s\n", l,
|
||||
DPRINTF(("l = %d, r = %" SIZE_T_FORMAT
|
||||
"u, s = %s\n", l,
|
||||
CDF_ROUND(l, sizeof(l)),
|
||||
inp[i].pi_str.s_buf));
|
||||
l = 4 + (uint32_t)CDF_ROUND(l, sizeof(l));
|
||||
o += l >> 2;
|
||||
if (l & 1)
|
||||
l++;
|
||||
o += l >> 1;
|
||||
if (q + o >= e)
|
||||
goto out;
|
||||
o4 = o * sizeof(uint32_t);
|
||||
}
|
||||
i--;
|
||||
@@ -896,7 +925,7 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
|
||||
unknown:
|
||||
DPRINTF(("Don't know how to deal with %x\n",
|
||||
inp[i].pi_type));
|
||||
goto out;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -935,8 +964,9 @@ cdf_unpack_summary_info(const cdf_stream_t *sst, const cdf_header_t *h,
|
||||
return -1;
|
||||
}
|
||||
if (cdf_read_property_info(sst, h, CDF_TOLE4(sd->sd_offset),
|
||||
info, count, &maxcount) == -1)
|
||||
info, count, &maxcount) == -1) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1061,14 +1091,14 @@ cdf_dump_sat(const char *prefix, const cdf_sat_t *sat, size_t size)
|
||||
size_t i, j, s = size / sizeof(cdf_secid_t);
|
||||
|
||||
for (i = 0; i < sat->sat_len; i++) {
|
||||
(void)fprintf(stderr, "%s[%" SIZE_T_FORMAT "u]:\n%.6d: ",
|
||||
prefix, i, i * s);
|
||||
(void)fprintf(stderr, "%s[%" SIZE_T_FORMAT "u]:\n%.6"
|
||||
SIZE_T_FORMAT "u: ", prefix, i, i * s);
|
||||
for (j = 0; j < s; j++) {
|
||||
(void)fprintf(stderr, "%5d, ",
|
||||
CDF_TOLE4(sat->sat_tab[s * i + j]));
|
||||
if ((j + 1) % 10 == 0)
|
||||
(void)fprintf(stderr, "\n%.6d: ",
|
||||
i * s + j + 1);
|
||||
(void)fprintf(stderr, "\n%.6" SIZE_T_FORMAT
|
||||
"u: ", i * s + j + 1);
|
||||
}
|
||||
(void)fprintf(stderr, "\n");
|
||||
}
|
||||
@@ -1087,7 +1117,8 @@ cdf_dump(void *v, size_t len)
|
||||
if (j == 16) {
|
||||
j = 0;
|
||||
abuf[15] = '\0';
|
||||
(void)fprintf(stderr, "%s\n%.4x: ", abuf, i + 1);
|
||||
(void)fprintf(stderr, "%s\n%.4" SIZE_T_FORMAT "x: ",
|
||||
abuf, i + 1);
|
||||
}
|
||||
}
|
||||
(void)fprintf(stderr, "\n");
|
||||
@@ -1185,6 +1216,14 @@ cdf_dump_property_info(const cdf_property_info_t *info, size_t count)
|
||||
(void)fprintf(stderr, "unsigned 32 [%u]\n",
|
||||
info[i].pi_u32);
|
||||
break;
|
||||
case CDF_FLOAT:
|
||||
(void)fprintf(stderr, "float [%g]\n",
|
||||
info[i].pi_f);
|
||||
break;
|
||||
case CDF_DOUBLE:
|
||||
(void)fprintf(stderr, "double [%g]\n",
|
||||
info[i].pi_d);
|
||||
break;
|
||||
case CDF_LENGTH32_STRING:
|
||||
(void)fprintf(stderr, "string %u [%.*s]\n",
|
||||
info[i].pi_str.s_len,
|
||||
|
||||
176
external/bsd/file/dist/src/cdf.h
vendored
176
external/bsd/file/dist/src/cdf.h
vendored
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: cdf.h,v 1.1.1.2 2011/05/12 20:46:55 christos Exp $ */
|
||||
/* $NetBSD: cdf.h,v 1.1.1.3 2012/02/22 17:48:26 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 Christos Zoulas
|
||||
@@ -53,136 +53,140 @@ typedef int32_t cdf_secid_t;
|
||||
|
||||
#define CDF_SECID_NULL 0
|
||||
#define CDF_SECID_FREE -1
|
||||
#define CDF_SECID_END_OF_CHAIN -2
|
||||
#define CDF_SECID_SECTOR_ALLOCATION_TABLE -3
|
||||
#define CDF_SECID_END_OF_CHAIN -2
|
||||
#define CDF_SECID_SECTOR_ALLOCATION_TABLE -3
|
||||
#define CDF_SECID_MASTER_SECTOR_ALLOCATION_TABLE -4
|
||||
|
||||
typedef struct {
|
||||
uint64_t h_magic;
|
||||
uint64_t h_magic;
|
||||
#define CDF_MAGIC 0xE11AB1A1E011CFD0LL
|
||||
uint64_t h_uuid[2];
|
||||
uint16_t h_revision;
|
||||
uint16_t h_version;
|
||||
uint16_t h_byte_order;
|
||||
uint16_t h_sec_size_p2;
|
||||
uint16_t h_short_sec_size_p2;
|
||||
uint8_t h_unused0[10];
|
||||
uint32_t h_num_sectors_in_sat;
|
||||
uint32_t h_secid_first_directory;
|
||||
uint8_t h_unused1[4];
|
||||
uint32_t h_min_size_standard_stream;
|
||||
cdf_secid_t h_secid_first_sector_in_short_sat;
|
||||
uint32_t h_num_sectors_in_short_sat;
|
||||
cdf_secid_t h_secid_first_sector_in_master_sat;
|
||||
uint32_t h_num_sectors_in_master_sat;
|
||||
cdf_secid_t h_master_sat[436/4];
|
||||
uint64_t h_uuid[2];
|
||||
uint16_t h_revision;
|
||||
uint16_t h_version;
|
||||
uint16_t h_byte_order;
|
||||
uint16_t h_sec_size_p2;
|
||||
uint16_t h_short_sec_size_p2;
|
||||
uint8_t h_unused0[10];
|
||||
uint32_t h_num_sectors_in_sat;
|
||||
uint32_t h_secid_first_directory;
|
||||
uint8_t h_unused1[4];
|
||||
uint32_t h_min_size_standard_stream;
|
||||
cdf_secid_t h_secid_first_sector_in_short_sat;
|
||||
uint32_t h_num_sectors_in_short_sat;
|
||||
cdf_secid_t h_secid_first_sector_in_master_sat;
|
||||
uint32_t h_num_sectors_in_master_sat;
|
||||
cdf_secid_t h_master_sat[436/4];
|
||||
} cdf_header_t;
|
||||
|
||||
#define CDF_SEC_SIZE(h) (1 << (h)->h_sec_size_p2)
|
||||
#define CDF_SEC_SIZE(h) ((size_t)(1 << (h)->h_sec_size_p2))
|
||||
#define CDF_SEC_POS(h, secid) (CDF_SEC_SIZE(h) + (secid) * CDF_SEC_SIZE(h))
|
||||
#define CDF_SHORT_SEC_SIZE(h) (1 << (h)->h_short_sec_size_p2)
|
||||
#define CDF_SHORT_SEC_SIZE(h) ((size_t)(1 << (h)->h_short_sec_size_p2))
|
||||
#define CDF_SHORT_SEC_POS(h, secid) ((secid) * CDF_SHORT_SEC_SIZE(h))
|
||||
|
||||
typedef int32_t cdf_dirid_t;
|
||||
typedef int32_t cdf_dirid_t;
|
||||
#define CDF_DIRID_NULL -1
|
||||
|
||||
typedef int64_t cdf_timestamp_t;
|
||||
typedef int64_t cdf_timestamp_t;
|
||||
#define CDF_BASE_YEAR 1601
|
||||
#define CDF_TIME_PREC 10000000
|
||||
|
||||
typedef struct {
|
||||
uint16_t d_name[32];
|
||||
uint16_t d_namelen;
|
||||
uint8_t d_type;
|
||||
uint16_t d_name[32];
|
||||
uint16_t d_namelen;
|
||||
uint8_t d_type;
|
||||
#define CDF_DIR_TYPE_EMPTY 0
|
||||
#define CDF_DIR_TYPE_USER_STORAGE 1
|
||||
#define CDF_DIR_TYPE_USER_STREAM 2
|
||||
#define CDF_DIR_TYPE_LOCKBYTES 3
|
||||
#define CDF_DIR_TYPE_PROPERTY 4
|
||||
#define CDF_DIR_TYPE_ROOT_STORAGE 5
|
||||
uint8_t d_color;
|
||||
#define CDF_DIR_TYPE_USER_STORAGE 1
|
||||
#define CDF_DIR_TYPE_USER_STREAM 2
|
||||
#define CDF_DIR_TYPE_LOCKBYTES 3
|
||||
#define CDF_DIR_TYPE_PROPERTY 4
|
||||
#define CDF_DIR_TYPE_ROOT_STORAGE 5
|
||||
uint8_t d_color;
|
||||
#define CDF_DIR_COLOR_READ 0
|
||||
#define CDF_DIR_COLOR_BLACK 1
|
||||
cdf_dirid_t d_left_child;
|
||||
cdf_dirid_t d_right_child;
|
||||
cdf_dirid_t d_storage;
|
||||
uint64_t d_storage_uuid[2];
|
||||
uint32_t d_flags;
|
||||
cdf_timestamp_t d_created;
|
||||
cdf_timestamp_t d_modified;
|
||||
cdf_secid_t d_stream_first_sector;
|
||||
uint32_t d_size;
|
||||
uint32_t d_unused0;
|
||||
cdf_dirid_t d_left_child;
|
||||
cdf_dirid_t d_right_child;
|
||||
cdf_dirid_t d_storage;
|
||||
uint64_t d_storage_uuid[2];
|
||||
uint32_t d_flags;
|
||||
cdf_timestamp_t d_created;
|
||||
cdf_timestamp_t d_modified;
|
||||
cdf_secid_t d_stream_first_sector;
|
||||
uint32_t d_size;
|
||||
uint32_t d_unused0;
|
||||
} cdf_directory_t;
|
||||
|
||||
#define CDF_DIRECTORY_SIZE 128
|
||||
|
||||
typedef struct {
|
||||
cdf_secid_t *sat_tab;
|
||||
size_t sat_len;
|
||||
cdf_secid_t *sat_tab;
|
||||
size_t sat_len;
|
||||
} cdf_sat_t;
|
||||
|
||||
typedef struct {
|
||||
cdf_directory_t *dir_tab;
|
||||
size_t dir_len;
|
||||
cdf_directory_t *dir_tab;
|
||||
size_t dir_len;
|
||||
} cdf_dir_t;
|
||||
|
||||
typedef struct {
|
||||
void *sst_tab;
|
||||
size_t sst_len;
|
||||
size_t sst_dirlen;
|
||||
void *sst_tab;
|
||||
size_t sst_len;
|
||||
size_t sst_dirlen;
|
||||
} cdf_stream_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t cl_dword;
|
||||
uint16_t cl_word[2];
|
||||
uint8_t cl_two[2];
|
||||
uint8_t cl_six[6];
|
||||
uint32_t cl_dword;
|
||||
uint16_t cl_word[2];
|
||||
uint8_t cl_two[2];
|
||||
uint8_t cl_six[6];
|
||||
} cdf_classid_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t si_byte_order;
|
||||
uint16_t si_zero;
|
||||
uint16_t si_os_version;
|
||||
uint16_t si_os;
|
||||
cdf_classid_t si_class;
|
||||
uint32_t si_count;
|
||||
uint16_t si_byte_order;
|
||||
uint16_t si_zero;
|
||||
uint16_t si_os_version;
|
||||
uint16_t si_os;
|
||||
cdf_classid_t si_class;
|
||||
uint32_t si_count;
|
||||
} cdf_summary_info_header_t;
|
||||
|
||||
#define CDF_SECTION_DECLARATION_OFFSET 0x1c
|
||||
|
||||
typedef struct {
|
||||
cdf_classid_t sd_class;
|
||||
uint32_t sd_offset;
|
||||
cdf_classid_t sd_class;
|
||||
uint32_t sd_offset;
|
||||
} cdf_section_declaration_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t sh_len;
|
||||
uint32_t sh_properties;
|
||||
uint32_t sh_len;
|
||||
uint32_t sh_properties;
|
||||
} cdf_section_header_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t pi_id;
|
||||
uint32_t pi_type;
|
||||
union {
|
||||
uint16_t _pi_u16;
|
||||
int16_t _pi_s16;
|
||||
uint32_t _pi_u32;
|
||||
int32_t _pi_s32;
|
||||
uint64_t _pi_u64;
|
||||
int64_t _pi_s64;
|
||||
cdf_timestamp_t _pi_tp;
|
||||
struct {
|
||||
uint32_t s_len;
|
||||
const char *s_buf;
|
||||
} _pi_str;
|
||||
} pi_val;
|
||||
uint32_t pi_id;
|
||||
uint32_t pi_type;
|
||||
union {
|
||||
uint16_t _pi_u16;
|
||||
int16_t _pi_s16;
|
||||
uint32_t _pi_u32;
|
||||
int32_t _pi_s32;
|
||||
uint64_t _pi_u64;
|
||||
int64_t _pi_s64;
|
||||
cdf_timestamp_t _pi_tp;
|
||||
float _pi_f;
|
||||
double _pi_d;
|
||||
struct {
|
||||
uint32_t s_len;
|
||||
const char *s_buf;
|
||||
} _pi_str;
|
||||
} pi_val;
|
||||
#define pi_u64 pi_val._pi_u64
|
||||
#define pi_s64 pi_val._pi_s64
|
||||
#define pi_u32 pi_val._pi_u32
|
||||
#define pi_s32 pi_val._pi_s32
|
||||
#define pi_u16 pi_val._pi_u16
|
||||
#define pi_s16 pi_val._pi_s16
|
||||
#define pi_f pi_val._pi_f
|
||||
#define pi_d pi_val._pi_d
|
||||
#define pi_tp pi_val._pi_tp
|
||||
#define pi_str pi_val._pi_str
|
||||
} cdf_property_info_t;
|
||||
@@ -191,13 +195,13 @@ typedef struct {
|
||||
|
||||
/* Variant type definitions */
|
||||
#define CDF_EMPTY 0x00000000
|
||||
#define CDF_NULL 0x00000001
|
||||
#define CDF_NULL 0x00000001
|
||||
#define CDF_SIGNED16 0x00000002
|
||||
#define CDF_SIGNED32 0x00000003
|
||||
#define CDF_FLOAT 0x00000004
|
||||
#define CDF_DOUBLE 0x00000005
|
||||
#define CDF_CY 0x00000006
|
||||
#define CDF_DATE 0x00000007
|
||||
#define CDF_DATE 0x00000007
|
||||
#define CDF_BSTR 0x00000008
|
||||
#define CDF_DISPATCH 0x00000009
|
||||
#define CDF_ERROR 0x0000000a
|
||||
@@ -208,7 +212,7 @@ typedef struct {
|
||||
#define CDF_SIGNED8 0x00000010
|
||||
#define CDF_UNSIGNED8 0x00000011
|
||||
#define CDF_UNSIGNED16 0x00000012
|
||||
#define CDF_UNSIGNED32 0x00000013
|
||||
#define CDF_UNSIGNED32 0x00000013
|
||||
#define CDF_SIGNED64 0x00000014
|
||||
#define CDF_UNSIGNED64 0x00000015
|
||||
#define CDF_INT 0x00000016
|
||||
@@ -243,7 +247,7 @@ typedef struct {
|
||||
#define CDF_PROPERTY_SUBJECT 0x00000003
|
||||
#define CDF_PROPERTY_AUTHOR 0x00000004
|
||||
#define CDF_PROPERTY_KEYWORDS 0x00000005
|
||||
#define CDF_PROPERTY_COMMENTS 0x00000006
|
||||
#define CDF_PROPERTY_COMMENTS 0x00000006
|
||||
#define CDF_PROPERTY_TEMPLATE 0x00000007
|
||||
#define CDF_PROPERTY_LAST_SAVED_BY 0x00000008
|
||||
#define CDF_PROPERTY_REVISION_NUMBER 0x00000009
|
||||
@@ -260,9 +264,9 @@ typedef struct {
|
||||
#define CDF_PROPERTY_LOCALE_ID 0x80000000
|
||||
|
||||
typedef struct {
|
||||
int i_fd;
|
||||
const unsigned char *i_buf;
|
||||
size_t i_len;
|
||||
int i_fd;
|
||||
const unsigned char *i_buf;
|
||||
size_t i_len;
|
||||
} cdf_info_t;
|
||||
|
||||
struct timespec;
|
||||
|
||||
8
external/bsd/file/dist/src/cdf_time.c
vendored
8
external/bsd/file/dist/src/cdf_time.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: cdf_time.c,v 1.3 2011/05/13 01:52:13 christos Exp $ */
|
||||
/* $NetBSD: cdf_time.c,v 1.4 2012/02/22 17:53:51 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 Christos Zoulas
|
||||
@@ -30,9 +30,9 @@
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
FILE_RCSID("@(#)$File: cdf_time.c,v 1.10 2011/02/10 17:03:16 christos Exp $")
|
||||
FILE_RCSID("@(#)$File: cdf_time.c,v 1.11 2011/12/13 13:48:41 christos Exp $")
|
||||
#else
|
||||
__RCSID("$NetBSD: cdf_time.c,v 1.3 2011/05/13 01:52:13 christos Exp $");
|
||||
__RCSID("$NetBSD: cdf_time.c,v 1.4 2012/02/22 17:53:51 christos Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -127,7 +127,7 @@ cdf_timestamp_to_timespec(struct timespec *ts, cdf_timestamp_t t)
|
||||
tm.tm_year = (int)(CDF_BASE_YEAR + (t / 365));
|
||||
|
||||
rdays = cdf_getdays(tm.tm_year);
|
||||
t -= rdays;
|
||||
t -= rdays - 1;
|
||||
tm.tm_mday = cdf_getday(tm.tm_year, (int)t);
|
||||
tm.tm_mon = cdf_getmonth(tm.tm_year, (int)t);
|
||||
tm.tm_wday = 0;
|
||||
|
||||
9
external/bsd/file/dist/src/compress.c
vendored
9
external/bsd/file/dist/src/compress.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: compress.c,v 1.4 2011/09/16 21:06:26 christos Exp $ */
|
||||
/* $NetBSD: compress.c,v 1.5 2012/02/22 17:53:51 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
@@ -38,9 +38,9 @@
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
FILE_RCSID("@(#)$File: compress.c,v 1.67 2011/09/01 12:12:37 christos Exp $")
|
||||
FILE_RCSID("@(#)$File: compress.c,v 1.68 2011/12/08 12:38:24 rrt Exp $")
|
||||
#else
|
||||
__RCSID("$NetBSD: compress.c,v 1.4 2011/09/16 21:06:26 christos Exp $");
|
||||
__RCSID("$NetBSD: compress.c,v 1.5 2012/02/22 17:53:51 christos Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -140,8 +140,7 @@ file_zmagic(struct magic_set *ms, int fd, const char *name,
|
||||
}
|
||||
}
|
||||
error:
|
||||
if (newbuf)
|
||||
free(newbuf);
|
||||
free(newbuf);
|
||||
ms->flags |= MAGIC_COMPRESS;
|
||||
return rv;
|
||||
}
|
||||
|
||||
11
external/bsd/file/dist/src/encoding.c
vendored
11
external/bsd/file/dist/src/encoding.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: encoding.c,v 1.1.1.2 2011/05/12 20:46:52 christos Exp $ */
|
||||
/* $NetBSD: encoding.c,v 1.1.1.3 2012/02/22 17:48:23 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
@@ -38,9 +38,9 @@
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
FILE_RCSID("@(#)$File: encoding.c,v 1.5 2010/07/21 16:47:17 christos Exp $")
|
||||
FILE_RCSID("@(#)$File: encoding.c,v 1.7 2012/01/24 19:02:02 christos Exp $")
|
||||
#else
|
||||
__RCSID("$NetBSD: encoding.c,v 1.1.1.2 2011/05/12 20:46:52 christos Exp $");
|
||||
__RCSID("$NetBSD: encoding.c,v 1.1.1.3 2012/02/22 17:48:23 christos Exp $");
|
||||
#endif
|
||||
#endif /* lint */
|
||||
|
||||
@@ -77,6 +77,7 @@ file_encoding(struct magic_set *ms, const unsigned char *buf, size_t nbytes, uni
|
||||
int rv = 1, ucs_type;
|
||||
unsigned char *nbuf = NULL;
|
||||
|
||||
*type = "text";
|
||||
mlen = (nbytes + 1) * sizeof(nbuf[0]);
|
||||
if ((nbuf = CAST(unsigned char *, calloc((size_t)1, mlen))) == NULL) {
|
||||
file_oomem(ms, mlen);
|
||||
@@ -88,7 +89,6 @@ file_encoding(struct magic_set *ms, const unsigned char *buf, size_t nbytes, uni
|
||||
goto done;
|
||||
}
|
||||
|
||||
*type = "text";
|
||||
if (looks_ascii(buf, nbytes, *ubuf, ulen)) {
|
||||
DPRINTF(("ascii %" SIZE_T_FORMAT "u\n", *ulen));
|
||||
*code = "ASCII";
|
||||
@@ -139,8 +139,7 @@ file_encoding(struct magic_set *ms, const unsigned char *buf, size_t nbytes, uni
|
||||
}
|
||||
|
||||
done:
|
||||
if (nbuf)
|
||||
free(nbuf);
|
||||
free(nbuf);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
8
external/bsd/file/dist/src/file.c
vendored
8
external/bsd/file/dist/src/file.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: file.c,v 1.1.1.2 2011/05/12 20:46:56 christos Exp $ */
|
||||
/* $NetBSD: file.c,v 1.1.1.3 2012/02/22 17:48:26 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
@@ -35,9 +35,9 @@
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
FILE_RCSID("@(#)$File: file.c,v 1.144 2011/05/10 17:08:14 christos Exp $")
|
||||
FILE_RCSID("@(#)$File: file.c,v 1.145 2011/12/08 12:12:46 rrt Exp $")
|
||||
#else
|
||||
__RCSID("$NetBSD: file.c,v 1.1.1.2 2011/05/12 20:46:56 christos Exp $");
|
||||
__RCSID("$NetBSD: file.c,v 1.1.1.3 2012/02/22 17:48:26 christos Exp $");
|
||||
#endif
|
||||
#endif /* lint */
|
||||
|
||||
@@ -122,7 +122,7 @@ private const struct {
|
||||
{ "soft", MAGIC_NO_CHECK_SOFT },
|
||||
{ "tar", MAGIC_NO_CHECK_TAR },
|
||||
{ "text", MAGIC_NO_CHECK_TEXT }, /* synonym for ascii */
|
||||
{ "tokens", MAGIC_NO_CHECK_TOKENS },
|
||||
{ "tokens", MAGIC_NO_CHECK_TOKENS }, /* OBSOLETE: ignored for backwards compatibility */
|
||||
};
|
||||
|
||||
private char *progname; /* used throughout */
|
||||
|
||||
21
external/bsd/file/dist/src/file.h
vendored
21
external/bsd/file/dist/src/file.h
vendored
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: file.h,v 1.5 2011/09/16 21:06:26 christos Exp $ */
|
||||
/* $NetBSD: file.h,v 1.6 2012/02/22 17:53:51 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
@@ -29,18 +29,12 @@
|
||||
*/
|
||||
/*
|
||||
* file.h - definitions for file(1) program
|
||||
* @(#)$File: file.h,v 1.133 2011/05/13 22:15:40 christos Exp $
|
||||
* @(#)$File: file.h,v 1.135 2011/09/20 15:30:14 christos Exp $
|
||||
*/
|
||||
|
||||
#ifndef __file_h__
|
||||
#define __file_h__
|
||||
|
||||
#ifdef __minix
|
||||
/* LSC We are being compiled on a minix host, for some reasons
|
||||
* this is not included fast enough, so ugly patch: */
|
||||
#include <sys/featuretest.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
@@ -94,6 +88,10 @@
|
||||
#endif
|
||||
#define public
|
||||
|
||||
#ifndef __arraycount
|
||||
#define __arraycount(a) (sizeof(a) / sizeof(a[0]))
|
||||
#endif
|
||||
|
||||
#ifndef __GNUC_PREREQ__
|
||||
#ifdef __GNUC__
|
||||
#define __GNUC_PREREQ__(x, y) \
|
||||
@@ -409,15 +407,16 @@ protected int file_trycdf(struct magic_set *, int, const unsigned char *,
|
||||
protected int file_zmagic(struct magic_set *, int, const char *,
|
||||
const unsigned char *, size_t);
|
||||
#endif
|
||||
protected int file_ascmagic(struct magic_set *, const unsigned char *, size_t);
|
||||
protected int file_ascmagic(struct magic_set *, const unsigned char *, size_t,
|
||||
int);
|
||||
protected int file_ascmagic_with_encoding(struct magic_set *,
|
||||
const unsigned char *, size_t, unichar *, size_t, const char *,
|
||||
const char *);
|
||||
const char *, int);
|
||||
protected int file_encoding(struct magic_set *, const unsigned char *, size_t,
|
||||
unichar **, size_t *, const char **, const char **, const char **);
|
||||
protected int file_is_tar(struct magic_set *, const unsigned char *, size_t);
|
||||
protected int file_softmagic(struct magic_set *, const unsigned char *, size_t,
|
||||
int);
|
||||
int, int);
|
||||
protected struct mlist *file_apprentice(struct magic_set *, const char *, int);
|
||||
protected uint64_t file_signextend(struct magic_set *, struct magic *,
|
||||
uint64_t);
|
||||
|
||||
19
external/bsd/file/dist/src/funcs.c
vendored
19
external/bsd/file/dist/src/funcs.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: funcs.c,v 1.3 2011/05/13 01:52:13 christos Exp $ */
|
||||
/* $NetBSD: funcs.c,v 1.4 2012/02/22 17:53:51 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) Christos Zoulas 2003.
|
||||
@@ -30,9 +30,9 @@
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
FILE_RCSID("@(#)$File: funcs.c,v 1.57 2011/05/11 01:02:41 christos Exp $")
|
||||
FILE_RCSID("@(#)$File: funcs.c,v 1.60 2011/12/08 12:38:24 rrt Exp $")
|
||||
#else
|
||||
__RCSID("$NetBSD: funcs.c,v 1.3 2011/05/13 01:52:13 christos Exp $");
|
||||
__RCSID("$NetBSD: funcs.c,v 1.4 2012/02/22 17:53:51 christos Exp $");
|
||||
#endif
|
||||
#endif /* lint */
|
||||
|
||||
@@ -235,7 +235,8 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__u
|
||||
|
||||
/* try soft magic tests */
|
||||
if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0)
|
||||
if ((m = file_softmagic(ms, ubuf, nb, BINTEST)) != 0) {
|
||||
if ((m = file_softmagic(ms, ubuf, nb, BINTEST,
|
||||
looks_text)) != 0) {
|
||||
if ((ms->flags & MAGIC_DEBUG) != 0)
|
||||
(void)fprintf(stderr, "softmagic %d\n", m);
|
||||
#ifdef BUILTIN_ELF
|
||||
@@ -259,10 +260,10 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__u
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* try text properties (and possibly text tokens) */
|
||||
/* try text properties */
|
||||
if ((ms->flags & MAGIC_NO_CHECK_TEXT) == 0) {
|
||||
|
||||
if ((m = file_ascmagic(ms, ubuf, nb)) != 0) {
|
||||
if ((m = file_ascmagic(ms, ubuf, nb, looks_text)) != 0) {
|
||||
if ((ms->flags & MAGIC_DEBUG) != 0)
|
||||
(void)fprintf(stderr, "ascmagic %d\n", m);
|
||||
goto done;
|
||||
@@ -272,7 +273,8 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__u
|
||||
if ((ms->flags & MAGIC_NO_CHECK_ENCODING) == 0) {
|
||||
if (looks_text == 0)
|
||||
if ((m = file_ascmagic_with_encoding( ms, ubuf,
|
||||
nb, u8buf, ulen, code, type)) != 0) {
|
||||
nb, u8buf, ulen, code, type, looks_text))
|
||||
!= 0) {
|
||||
if ((ms->flags & MAGIC_DEBUG) != 0)
|
||||
(void)fprintf(stderr,
|
||||
"ascmagic/enc %d\n", m);
|
||||
@@ -295,8 +297,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__u
|
||||
if (file_printf(ms, "%s", code_mime) == -1)
|
||||
rv = -1;
|
||||
}
|
||||
if (u8buf)
|
||||
free(u8buf);
|
||||
free(u8buf);
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
|
||||
4
external/bsd/file/dist/src/getline.c
vendored
4
external/bsd/file/dist/src/getline.c
vendored
@@ -1,4 +1,6 @@
|
||||
/* $NetBSD: getline.c,v 1.1.1.1 2011/05/12 20:46:50 christos Exp $ */
|
||||
/* $NetBSD: getline.c,v 1.1.1.2 2012/02/22 17:48:20 christos Exp $ */
|
||||
|
||||
/* NetBSD: fgetln.c,v 1.9 2008/04/29 06:53:03 martin Exp */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2011 The NetBSD Foundation, Inc.
|
||||
|
||||
6
external/bsd/file/dist/src/getopt_long.c
vendored
6
external/bsd/file/dist/src/getopt_long.c
vendored
@@ -1,4 +1,6 @@
|
||||
/* $NetBSD: getopt_long.c,v 1.1.1.1 2009/05/08 16:35:05 christos Exp $ */
|
||||
/* $NetBSD: getopt_long.c,v 1.1.1.2 2012/02/22 17:48:18 christos Exp $ */
|
||||
|
||||
/* NetBSD: getopt_long.c,v 1.21.4.1 2008/01/09 01:34:14 matt Exp */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
@@ -35,7 +37,7 @@
|
||||
#if 0
|
||||
FILE_RCSID("@(#)$File: getopt_long.c,v 1.6 2009/02/13 18:48:05 christos Exp $")
|
||||
#else
|
||||
__RCSID("$NetBSD: getopt_long.c,v 1.1.1.1 2009/05/08 16:35:05 christos Exp $");
|
||||
__RCSID("$NetBSD: getopt_long.c,v 1.1.1.2 2012/02/22 17:48:18 christos Exp $");
|
||||
#endif
|
||||
#endif /* lint */
|
||||
|
||||
|
||||
14
external/bsd/file/dist/src/magic.h
vendored
14
external/bsd/file/dist/src/magic.h
vendored
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: magic.h,v 1.1.1.2 2011/05/12 20:46:49 christos Exp $ */
|
||||
/* $NetBSD: magic.h,v 1.1.1.3 2012/02/22 17:48:18 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) Christos Zoulas 2003.
|
||||
@@ -57,7 +57,17 @@
|
||||
#define MAGIC_NO_CHECK_ENCODING 0x200000 /* Don't check text encodings */
|
||||
|
||||
/* No built-in tests; only consult the magic file */
|
||||
#define MAGIC_NO_CHECK_BUILTIN 0x3fb000
|
||||
#define MAGIC_NO_CHECK_BUILTIN ( \
|
||||
MAGIC_NO_CHECK_COMPRESS | \
|
||||
MAGIC_NO_CHECK_TAR | \
|
||||
/* MAGIC_NO_CHECK_SOFT | */ \
|
||||
MAGIC_NO_CHECK_APPTYPE | \
|
||||
MAGIC_NO_CHECK_ELF | \
|
||||
MAGIC_NO_CHECK_TEXT | \
|
||||
MAGIC_NO_CHECK_CDF | \
|
||||
MAGIC_NO_CHECK_TOKENS | \
|
||||
MAGIC_NO_CHECK_ENCODING | \
|
||||
)
|
||||
|
||||
/* Defined for backwards compatibility (renamed) */
|
||||
#define MAGIC_NO_CHECK_ASCII MAGIC_NO_CHECK_TEXT
|
||||
|
||||
4
external/bsd/file/dist/src/mygetopt.h
vendored
4
external/bsd/file/dist/src/mygetopt.h
vendored
@@ -1,4 +1,6 @@
|
||||
/* $NetBSD: mygetopt.h,v 1.1.1.1 2009/05/08 16:35:06 christos Exp $ */
|
||||
/* $NetBSD: mygetopt.h,v 1.1.1.2 2012/02/22 17:48:20 christos Exp $ */
|
||||
|
||||
/* NetBSD: getopt.h,v 1.8 2007/11/06 19:21:18 christos Exp */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
|
||||
178
external/bsd/file/dist/src/names.h
vendored
178
external/bsd/file/dist/src/names.h
vendored
@@ -1,178 +0,0 @@
|
||||
/* $NetBSD: names.h,v 1.1.1.2 2011/05/12 20:46:54 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
* Software written by Ian F. Darwin and others;
|
||||
* maintained 1995-present by Christos Zoulas and others.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice immediately at the beginning of the file, without modification,
|
||||
* this list of conditions, and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Names.h - names and types used by ascmagic in file(1).
|
||||
* These tokens are here because they can appear anywhere in
|
||||
* the first HOWMANY bytes, while tokens in MAGIC must
|
||||
* appear at fixed offsets into the file. Don't make HOWMANY
|
||||
* too high unless you have a very fast CPU.
|
||||
*
|
||||
* $File: names.h,v 1.33 2010/10/08 21:58:44 christos Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
modified by Chris Lowth - 9 April 2000
|
||||
to add mime type strings to the types table.
|
||||
*/
|
||||
|
||||
/* these types are used to index the table 'types': keep em in sync! */
|
||||
#define L_C 0 /* first and foremost on UNIX */
|
||||
#define L_CC 1 /* Bjarne's postincrement */
|
||||
#define L_MAKE 2 /* Makefiles */
|
||||
#define L_PLI 3 /* PL/1 */
|
||||
#define L_MACH 4 /* some kinda assembler */
|
||||
#define L_ENG 5 /* English */
|
||||
#define L_PAS 6 /* Pascal */
|
||||
#define L_MAIL 7 /* Electronic mail */
|
||||
#define L_NEWS 8 /* Usenet Netnews */
|
||||
#define L_JAVA 9 /* Java code */
|
||||
#define L_HTML 10 /* HTML */
|
||||
#define L_BCPL 11 /* BCPL */
|
||||
#define L_M4 12 /* M4 */
|
||||
#define L_PO 13 /* PO */
|
||||
|
||||
static const struct {
|
||||
char human[48];
|
||||
char mime[16];
|
||||
} types[] = {
|
||||
{ "C program", "text/x-c", },
|
||||
{ "C++ program", "text/x-c++" },
|
||||
{ "make commands", "text/x-makefile" },
|
||||
{ "PL/1 program", "text/x-pl1" },
|
||||
{ "assembler program", "text/x-asm" },
|
||||
{ "English", "text/plain" },
|
||||
{ "Pascal program", "text/x-pascal" },
|
||||
{ "mail", "text/x-mail" },
|
||||
{ "news", "text/x-news" },
|
||||
{ "Java program", "text/x-java" },
|
||||
{ "HTML document", "text/html", },
|
||||
{ "BCPL program", "text/x-bcpl" },
|
||||
{ "M4 macro language pre-processor", "text/x-m4" },
|
||||
{ "PO (gettext message catalogue)", "text/x-po" },
|
||||
{ "cannot happen error on names.h/types", "error/x-error" }
|
||||
};
|
||||
|
||||
/*
|
||||
* XXX - how should we distinguish Java from C++?
|
||||
* The trick used in a Debian snapshot, of having "extends" or "implements"
|
||||
* as tags for Java, doesn't work very well, given that those keywords
|
||||
* are often preceded by "class", which flags it as C++.
|
||||
*
|
||||
* Perhaps we need to be able to say
|
||||
*
|
||||
* If "class" then
|
||||
*
|
||||
* if "extends" or "implements" then
|
||||
* Java
|
||||
* else
|
||||
* C++
|
||||
* endif
|
||||
*
|
||||
* Or should we use other keywords, such as "package" or "import"?
|
||||
* Unfortunately, Ada95 uses "package", and Modula-3 uses "import",
|
||||
* although I infer from the language spec at
|
||||
*
|
||||
* http://www.research.digital.com/SRC/m3defn/html/m3.html
|
||||
*
|
||||
* that Modula-3 uses "IMPORT" rather than "import", i.e. it must be
|
||||
* in all caps.
|
||||
*
|
||||
* So, for now, we go with "import". We must put it before the C++
|
||||
* stuff, so that we don't misidentify Java as C++. Not using "package"
|
||||
* means we won't identify stuff that defines a package but imports
|
||||
* nothing; hopefully, very little Java code imports nothing (one of the
|
||||
* reasons for doing OO programming is to import as much as possible
|
||||
* and write only what you need to, right?).
|
||||
*
|
||||
* Unfortunately, "import" may cause us to misidentify English text
|
||||
* as Java, as it comes after "the" and "The". Perhaps we need a fancier
|
||||
* heuristic to identify Java?
|
||||
*/
|
||||
static const struct names {
|
||||
char name[14];
|
||||
unsigned char type;
|
||||
unsigned char score;
|
||||
|
||||
} names[] = {
|
||||
/* These must be sorted by eye for optimal hit rate */
|
||||
/* Add to this list only after substantial meditation */
|
||||
{"msgid", L_PO, 1 },
|
||||
{"dnl", L_M4, 2 },
|
||||
{"import", L_JAVA, 2 },
|
||||
{"\"libhdr\"", L_BCPL, 2 },
|
||||
{"\"LIBHDR\"", L_BCPL, 2 },
|
||||
{"//", L_CC, 2 },
|
||||
{"template", L_CC, 1 },
|
||||
{"virtual", L_CC, 1 },
|
||||
{"class", L_CC, 2 },
|
||||
{"public:", L_CC, 2 },
|
||||
{"private:", L_CC, 2 },
|
||||
{"/*", L_C, 2 }, /* must precede "The", "the", etc. */
|
||||
{"#include", L_C, 2 },
|
||||
{"char", L_C, 2 },
|
||||
{"The", L_ENG, 2 },
|
||||
{"the", L_ENG, 2 },
|
||||
{"double", L_C, 1 },
|
||||
{"extern", L_C, 2 },
|
||||
{"float", L_C, 1 },
|
||||
{"struct", L_C, 1 },
|
||||
{"union", L_C, 1 },
|
||||
{"main(", L_C, 2 },
|
||||
{"CFLAGS", L_MAKE, 2 },
|
||||
{"LDFLAGS", L_MAKE, 2 },
|
||||
{"all:", L_MAKE, 2 },
|
||||
{".PRECIOUS", L_MAKE, 2 },
|
||||
{".ascii", L_MACH, 2 },
|
||||
{".asciiz", L_MACH, 2 },
|
||||
{".byte", L_MACH, 2 },
|
||||
{".even", L_MACH, 2 },
|
||||
{".globl", L_MACH, 2 },
|
||||
{".text", L_MACH, 2 },
|
||||
{"clr", L_MACH, 2 },
|
||||
{"(input,", L_PAS, 2 },
|
||||
{"program", L_PAS, 1 },
|
||||
{"record", L_PAS, 1 },
|
||||
{"dcl", L_PLI, 2 },
|
||||
{"Received:", L_MAIL, 2 },
|
||||
{">From", L_MAIL, 2 },
|
||||
{"Return-Path:",L_MAIL, 2 },
|
||||
{"Cc:", L_MAIL, 2 },
|
||||
{"Newsgroups:", L_NEWS, 2 },
|
||||
{"Path:", L_NEWS, 2 },
|
||||
{"Organization:",L_NEWS, 2 },
|
||||
{"href=", L_HTML, 2 },
|
||||
{"HREF=", L_HTML, 2 },
|
||||
{"<body", L_HTML, 2 },
|
||||
{"<BODY", L_HTML, 2 },
|
||||
{"<html", L_HTML, 2 },
|
||||
{"<HTML", L_HTML, 2 },
|
||||
{"<!--", L_HTML, 2 },
|
||||
};
|
||||
#define NNAMES (sizeof(names)/sizeof(struct names))
|
||||
28
external/bsd/file/dist/src/print.c
vendored
28
external/bsd/file/dist/src/print.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: print.c,v 1.3 2011/09/16 21:06:26 christos Exp $ */
|
||||
/* $NetBSD: print.c,v 1.4 2012/02/22 17:53:51 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
@@ -35,9 +35,9 @@
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
FILE_RCSID("@(#)$File: print.c,v 1.70 2011/08/14 09:03:12 christos Exp $")
|
||||
FILE_RCSID("@(#)$File: print.c,v 1.71 2011/09/20 15:28:09 christos Exp $")
|
||||
#else
|
||||
__RCSID("$NetBSD: print.c,v 1.3 2011/09/16 21:06:26 christos Exp $");
|
||||
__RCSID("$NetBSD: print.c,v 1.4 2012/02/22 17:53:51 christos Exp $");
|
||||
#endif
|
||||
#endif /* lint */
|
||||
|
||||
@@ -57,8 +57,8 @@ file_mdump(struct magic *m)
|
||||
{
|
||||
private const char optyp[] = { FILE_OPS };
|
||||
|
||||
(void) fprintf(stderr, "%.*s %u", (m->cont_level & 7) + 1, ">>>>>>>>",
|
||||
m->offset);
|
||||
(void) fprintf(stderr, "%u: %.*s %u", m->lineno,
|
||||
(m->cont_level & 7) + 1, ">>>>>>>>", m->offset);
|
||||
|
||||
if (m->flag & INDIR) {
|
||||
(void) fprintf(stderr, "(%s,",
|
||||
@@ -93,6 +93,24 @@ file_mdump(struct magic *m)
|
||||
(void) fputc(CHAR_IGNORE_UPPERCASE, stderr);
|
||||
if (m->str_flags & REGEX_OFFSET_START)
|
||||
(void) fputc(CHAR_REGEX_OFFSET_START, stderr);
|
||||
if (m->str_flags & STRING_TEXTTEST)
|
||||
(void) fputc(CHAR_TEXTTEST, stderr);
|
||||
if (m->str_flags & STRING_BINTEST)
|
||||
(void) fputc(CHAR_BINTEST, stderr);
|
||||
if (m->str_flags & PSTRING_1_BE)
|
||||
(void) fputc(CHAR_PSTRING_1_BE, stderr);
|
||||
if (m->str_flags & PSTRING_2_BE)
|
||||
(void) fputc(CHAR_PSTRING_2_BE, stderr);
|
||||
if (m->str_flags & PSTRING_2_LE)
|
||||
(void) fputc(CHAR_PSTRING_2_LE, stderr);
|
||||
if (m->str_flags & PSTRING_4_BE)
|
||||
(void) fputc(CHAR_PSTRING_4_BE, stderr);
|
||||
if (m->str_flags & PSTRING_4_LE)
|
||||
(void) fputc(CHAR_PSTRING_4_LE, stderr);
|
||||
if (m->str_flags & PSTRING_LENGTH_INCLUDES_ITSELF)
|
||||
(void) fputc(
|
||||
CHAR_PSTRING_LENGTH_INCLUDES_ITSELF,
|
||||
stderr);
|
||||
}
|
||||
if (m->str_range)
|
||||
(void) fprintf(stderr, "/%u", m->str_range);
|
||||
|
||||
42
external/bsd/file/dist/src/readcdf.c
vendored
42
external/bsd/file/dist/src/readcdf.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: readcdf.c,v 1.6 2011/09/28 13:50:09 christos Exp $ */
|
||||
/* $NetBSD: readcdf.c,v 1.7 2012/02/22 17:53:51 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 Christos Zoulas
|
||||
@@ -29,9 +29,9 @@
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
FILE_RCSID("@(#)$File: readcdf.c,v 1.26 2011/08/26 13:38:28 christos Exp $")
|
||||
FILE_RCSID("@(#)$File: readcdf.c,v 1.29 2012/02/20 20:04:58 christos Exp $")
|
||||
#else
|
||||
__RCSID("$NetBSD: readcdf.c,v 1.6 2011/09/28 13:50:09 christos Exp $");
|
||||
__RCSID("$NetBSD: readcdf.c,v 1.7 2012/02/22 17:53:51 christos Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -82,6 +82,16 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
|
||||
info[i].pi_u32) == -1)
|
||||
return -1;
|
||||
break;
|
||||
case CDF_FLOAT:
|
||||
if (NOTMIME(ms) && file_printf(ms, ", %s: %g", buf,
|
||||
info[i].pi_f) == -1)
|
||||
return -1;
|
||||
break;
|
||||
case CDF_DOUBLE:
|
||||
if (NOTMIME(ms) && file_printf(ms, ", %s: %g", buf,
|
||||
info[i].pi_d) == -1)
|
||||
return -1;
|
||||
break;
|
||||
case CDF_LENGTH32_STRING:
|
||||
case CDF_LENGTH32_WSTRING:
|
||||
len = info[i].pi_str.s_len;
|
||||
@@ -154,9 +164,8 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
|
||||
if (!NOTMIME(ms)) {
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
if (file_printf(ms, "application/%s", str) == -1)
|
||||
return -1;
|
||||
|
||||
if (file_printf(ms, "application/%s", str) == -1)
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -174,30 +183,31 @@ cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h,
|
||||
return -1;
|
||||
|
||||
if (NOTMIME(ms)) {
|
||||
if (file_printf(ms, "Composite Document File V2 Document") == -1)
|
||||
if (file_printf(ms, "Composite Document File V2 Document")
|
||||
== -1)
|
||||
return -1;
|
||||
|
||||
if (file_printf(ms, ", %s Endian",
|
||||
si.si_byte_order == 0xfffe ? "Little" : "Big") == -1)
|
||||
return -1;
|
||||
return -2;
|
||||
switch (si.si_os) {
|
||||
case 2:
|
||||
if (file_printf(ms, ", Os: Windows, Version %d.%d",
|
||||
si.si_os_version & 0xff,
|
||||
(uint32_t)si.si_os_version >> 8) == -1)
|
||||
return -1;
|
||||
return -2;
|
||||
break;
|
||||
case 1:
|
||||
if (file_printf(ms, ", Os: MacOS, Version %d.%d",
|
||||
(uint32_t)si.si_os_version >> 8,
|
||||
si.si_os_version & 0xff) == -1)
|
||||
return -1;
|
||||
return -2;
|
||||
break;
|
||||
default:
|
||||
if (file_printf(ms, ", Os %d, Version: %d.%d", si.si_os,
|
||||
si.si_os_version & 0xff,
|
||||
(uint32_t)si.si_os_version >> 8) == -1)
|
||||
return -1;
|
||||
return -2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -205,7 +215,7 @@ cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h,
|
||||
m = cdf_file_property_info(ms, info, count);
|
||||
free(info);
|
||||
|
||||
return m;
|
||||
return m == -1 ? -2 : m;
|
||||
}
|
||||
|
||||
protected int
|
||||
@@ -274,7 +284,7 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
|
||||
#ifdef CDF_DEBUG
|
||||
cdf_dump_summary_info(&h, &scn);
|
||||
#endif
|
||||
if ((i = cdf_file_summary_info(ms, &h, &scn)) == -1)
|
||||
if ((i = cdf_file_summary_info(ms, &h, &scn)) < 0)
|
||||
expn = "Can't expand summary_info";
|
||||
if (i == 0) {
|
||||
const char *str = "vnd.ms-office";
|
||||
@@ -305,8 +315,10 @@ out1:
|
||||
free(sat.sat_tab);
|
||||
out0:
|
||||
if (i != 1) {
|
||||
if (file_printf(ms, "Composite Document File V2 Document") == -1)
|
||||
return -1;
|
||||
if (i == -1)
|
||||
if (file_printf(ms, "Composite Document File V2 Document")
|
||||
== -1)
|
||||
return -1;
|
||||
if (*expn)
|
||||
if (file_printf(ms, ", %s%s", corrupt, expn) == -1)
|
||||
return -1;
|
||||
|
||||
58
external/bsd/file/dist/src/softmagic.c
vendored
58
external/bsd/file/dist/src/softmagic.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: softmagic.c,v 1.4 2011/09/16 21:06:27 christos Exp $ */
|
||||
/* $NetBSD: softmagic.c,v 1.6 2012/04/07 17:30:56 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
@@ -35,9 +35,9 @@
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
FILE_RCSID("@(#)$File: softmagic.c,v 1.145 2011/05/13 22:15:40 christos Exp $")
|
||||
FILE_RCSID("@(#)$File: softmagic.c,v 1.147 2011/11/05 15:44:22 rrt Exp $")
|
||||
#else
|
||||
__RCSID("$NetBSD: softmagic.c,v 1.4 2011/09/16 21:06:27 christos Exp $");
|
||||
__RCSID("$NetBSD: softmagic.c,v 1.6 2012/04/07 17:30:56 christos Exp $");
|
||||
#endif
|
||||
#endif /* lint */
|
||||
|
||||
@@ -49,9 +49,9 @@ __RCSID("$NetBSD: softmagic.c,v 1.4 2011/09/16 21:06:27 christos Exp $");
|
||||
|
||||
|
||||
private int match(struct magic_set *, struct magic *, uint32_t,
|
||||
const unsigned char *, size_t, int);
|
||||
const unsigned char *, size_t, int, int);
|
||||
private int mget(struct magic_set *, const unsigned char *,
|
||||
struct magic *, size_t, unsigned int);
|
||||
struct magic *, size_t, unsigned int, int);
|
||||
private int magiccheck(struct magic_set *, struct magic *);
|
||||
private int32_t mprint(struct magic_set *, struct magic *);
|
||||
private int32_t moffset(struct magic_set *, struct magic *);
|
||||
@@ -72,12 +72,14 @@ private void cvt_64(union VALUETYPE *, const struct magic *);
|
||||
*/
|
||||
/*ARGSUSED1*/ /* nbytes passed for regularity, maybe need later */
|
||||
protected int
|
||||
file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes, int mode)
|
||||
file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
|
||||
int mode, int text)
|
||||
{
|
||||
struct mlist *ml;
|
||||
int rv;
|
||||
for (ml = ms->mlist->next; ml != ms->mlist; ml = ml->next)
|
||||
if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, mode)) != 0)
|
||||
if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, mode,
|
||||
text)) != 0)
|
||||
return rv;
|
||||
|
||||
return 0;
|
||||
@@ -112,7 +114,7 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes, in
|
||||
*/
|
||||
private int
|
||||
match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
|
||||
const unsigned char *s, size_t nbytes, int mode)
|
||||
const unsigned char *s, size_t nbytes, int mode, int text)
|
||||
{
|
||||
uint32_t magindex = 0;
|
||||
unsigned int cont_level = 0;
|
||||
@@ -129,7 +131,10 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
|
||||
int flush = 0;
|
||||
struct magic *m = &magic[magindex];
|
||||
|
||||
if ((m->flag & mode) != mode) {
|
||||
if ((IS_STRING(m->type) &&
|
||||
((text && (m->str_flags & (STRING_BINTEST | STRING_TEXTTEST)) == STRING_BINTEST) ||
|
||||
(!text && (m->str_flags & (STRING_TEXTTEST | STRING_BINTEST)) == STRING_TEXTTEST))) ||
|
||||
(m->flag & mode) != mode) {
|
||||
/* Skip sub-tests */
|
||||
while (magic[magindex + 1].cont_level != 0 &&
|
||||
++magindex < nmagic)
|
||||
@@ -141,7 +146,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
|
||||
ms->line = m->lineno;
|
||||
|
||||
/* if main entry matches, print it... */
|
||||
switch (mget(ms, s, m, nbytes, cont_level)) {
|
||||
switch (mget(ms, s, m, nbytes, cont_level, text)) {
|
||||
case -1:
|
||||
return -1;
|
||||
case 0:
|
||||
@@ -224,7 +229,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
switch (mget(ms, s, m, nbytes, cont_level)) {
|
||||
switch (mget(ms, s, m, nbytes, cont_level, text)) {
|
||||
case -1:
|
||||
return -1;
|
||||
case 0:
|
||||
@@ -1019,10 +1024,12 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
|
||||
|
||||
private int
|
||||
mget(struct magic_set *ms, const unsigned char *s,
|
||||
struct magic *m, size_t nbytes, unsigned int cont_level)
|
||||
struct magic *m, size_t nbytes, unsigned int cont_level, int text)
|
||||
{
|
||||
uint32_t offset = ms->offset;
|
||||
uint32_t count = m->str_range;
|
||||
int rv;
|
||||
char *sbuf, *rbuf;
|
||||
union VALUETYPE *p = &ms->ms_value;
|
||||
|
||||
if (mcopy(ms, p, m->type, m->flag & INDIR, s, offset, nbytes, count) == -1)
|
||||
@@ -1071,6 +1078,8 @@ mget(struct magic_set *ms, const unsigned char *s,
|
||||
(q->hl[3]<<8)|(q->hl[2]));
|
||||
break;
|
||||
}
|
||||
if ((ms->flags & MAGIC_DEBUG) != 0)
|
||||
fprintf(stderr, "indirect offs=%u\n", off);
|
||||
}
|
||||
switch (m->in_type) {
|
||||
case FILE_BYTE:
|
||||
@@ -1511,6 +1520,8 @@ mget(struct magic_set *ms, const unsigned char *s,
|
||||
|
||||
if (m->flag & INDIROFFADD) {
|
||||
offset += ms->c.li[cont_level-1].off;
|
||||
if ((ms->flags & MAGIC_DEBUG) != 0)
|
||||
fprintf(stderr, "indirect +offs=%u\n", offset);
|
||||
}
|
||||
if (mcopy(ms, p, m->type, 0, s, offset, nbytes, count) == -1)
|
||||
return -1;
|
||||
@@ -1578,13 +1589,26 @@ mget(struct magic_set *ms, const unsigned char *s,
|
||||
break;
|
||||
|
||||
case FILE_INDIRECT:
|
||||
if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
|
||||
file_printf(ms, "%s", m->desc) == -1)
|
||||
return -1;
|
||||
if (nbytes < offset)
|
||||
return 0;
|
||||
return file_softmagic(ms, s + offset, nbytes - offset,
|
||||
BINTEST);
|
||||
sbuf = ms->o.buf;
|
||||
ms->o.buf = NULL;
|
||||
rv = file_softmagic(ms, s + offset, nbytes - offset,
|
||||
BINTEST, text);
|
||||
if ((ms->flags & MAGIC_DEBUG) != 0)
|
||||
fprintf(stderr, "indirect @offs=%u[%d]\n", offset, rv);
|
||||
if (rv == 1) {
|
||||
rbuf = ms->o.buf;
|
||||
ms->o.buf = sbuf;
|
||||
if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
|
||||
file_printf(ms, m->desc, offset) == -1)
|
||||
return -1;
|
||||
if (file_printf(ms, "%s", rbuf) == -1)
|
||||
return -1;
|
||||
free(rbuf);
|
||||
} else
|
||||
ms->o.buf = sbuf;
|
||||
return rv;
|
||||
|
||||
case FILE_DEFAULT: /* nothing to check */
|
||||
default:
|
||||
|
||||
9
external/bsd/file/dist/src/vasprintf.c
vendored
9
external/bsd/file/dist/src/vasprintf.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: vasprintf.c,v 1.1.1.1 2009/05/08 16:35:05 christos Exp $ */
|
||||
/* $NetBSD: vasprintf.c,v 1.1.1.2 2012/02/22 17:48:20 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||
@@ -111,9 +111,9 @@ you use strange formats.
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
FILE_RCSID("@(#)$File: vasprintf.c,v 1.7 2009/02/03 20:27:52 christos Exp $")
|
||||
FILE_RCSID("@(#)$File: vasprintf.c,v 1.8 2011/12/08 12:38:24 rrt Exp $")
|
||||
#else
|
||||
__RCSID("$NetBSD: vasprintf.c,v 1.1.1.1 2009/05/08 16:35:05 christos Exp $");
|
||||
__RCSID("$NetBSD: vasprintf.c,v 1.1.1.2 2012/02/22 17:48:20 christos Exp $");
|
||||
#endif
|
||||
#endif /* lint */
|
||||
|
||||
@@ -614,8 +614,7 @@ static int core(xprintf_struct *s)
|
||||
return s->pseudo_len;
|
||||
|
||||
free_EOF:
|
||||
if (s->buffer_base != NULL)
|
||||
free(s->buffer_base);
|
||||
free(s->buffer_base);
|
||||
return EOF;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user