#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.99 2018/09/09 20:33:28 christos Exp $")
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.100 2018/10/15 16:29:16 christos Exp $")
#endif /* lint */
#include "magic.h"
const char *type = NULL;
bb = *b;
- bb.flen = trim_nuls(b->fbuf, b->flen);
+ bb.flen = trim_nuls(CAST(const unsigned char *, b->fbuf), b->flen);
/* If file doesn't look like any sort of text, give up. */
if (file_encoding(ms, &bb, &ubuf, &ulen, &code, &code_mime,
const char *type, int text)
{
struct buffer bb;
- const unsigned char *buf = b->fbuf;
+ const unsigned char *buf = CAST(const unsigned char *, b->fbuf);
size_t nbytes = b->flen;
unsigned char *utf8_buf = NULL, *utf8_end;
size_t mlen, i;
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: cdf.c,v 1.112 2018/10/01 18:45:39 christos Exp $")
+FILE_RCSID("@(#)$File: cdf.c,v 1.113 2018/10/15 16:29:16 christos Exp $")
#endif
#include <assert.h>
cdf_malloc(const char *file __attribute__((__unused__)),
size_t line __attribute__((__unused__)), size_t n)
{
- DPRINTF(("%s,%zu: %s %zu\n", file, line, __func__, n));
+ DPRINTF(("%s,%" SIZE_T_FORMAT "u: %s %" SIZE_T_FORMAT "u\n",
+ file, line, __func__, n));
return malloc(n);
}
cdf_realloc(const char *file __attribute__((__unused__)),
size_t line __attribute__((__unused__)), void *p, size_t n)
{
- DPRINTF(("%s,%zu: %s %zu\n", file, line, __func__, n));
+ DPRINTF(("%s,%" SIZE_T_FORMAT "u: %s %" SIZE_T_FORMAT "u\n",
+ file, line, __func__, n));
return realloc(p, n);
}
cdf_calloc(const char *file __attribute__((__unused__)),
size_t line __attribute__((__unused__)), size_t n, size_t u)
{
- DPRINTF(("%s,%zu: %s %zu %zu\n", file, line, __func__, n, u));
+ DPRINTF(("%s,%" SIZE_T_FORMAT "u: %s %" SIZE_T_FORMAT "u %"
+ SIZE_T_FORMAT "u\n", file, line, __func__, n, u));
return calloc(n, u);
}
if (sec < 0)
goto out;
if (i >= sat->sat_len) {
- DPRINTF(("Out of bounds reading MSA %" SIZE_T_FORMAT
- "u >= %" SIZE_T_FORMAT "u", i, sat->sat_len));
+ DPRINTF(("Out of bounds reading MSA %"
+ SIZE_T_FORMAT "u >= %" SIZE_T_FORMAT "u",
+ i, sat->sat_len));
goto out3;
}
if (cdf_read_sector(info, sat->sat_tab, ss * i, ss, h,
size_t newcount = *maxcount + incr;
if (newcount > CDF_PROP_LIMIT) {
- DPRINTF(("exceeded property limit %zu > %zu\n",
- newcount, CDF_PROP_LIMIT));
+ DPRINTF(("exceeded property limit %" SIZE_T_FORMAT "u > %"
+ SIZE_T_FORMAT "u\n", newcount, CDF_PROP_LIMIT));
goto out;
}
inp = CAST(cdf_property_info_t *,
inp[i].pi_str.s_buf = CAST(const char *,
CAST(const void *, &q[o4]));
- DPRINTF(("o=%zu l=%d(%" SIZE_T_FORMAT
- "u), t=%zu s=%s\n", o4, l,
- CDF_ROUND(l, sizeof(l)), left,
- inp[i].pi_str.s_buf));
+ DPRINTF(("o=%" SIZE_T_FORMAT "u l=%d(%"
+ SIZE_T_FORMAT "u), t=%" SIZE_T_FORMAT
+ "u s=%s\n", o4, l, CDF_ROUND(l, sizeof(l)),
+ left, inp[i].pi_str.s_buf));
if (l & 1)
l++;
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.112 2018/10/01 18:43:01 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.113 2018/10/15 16:29:16 christos Exp $")
#endif
#include "magic.h"
const void *magic;
size_t maglen;
const char **argv;
-
+ void *unused;
} compr[] = {
{ "\037\235", 2, gzip_args, NULL }, /* compressed */
/* Uncompress can get stuck; so use gzip first if we have it
int urv, prv, rv = 0;
int mime = ms->flags & MAGIC_MIME;
int fd = b->fd;
- const unsigned char *buf = b->fbuf;
+ const unsigned char *buf = CAST(const unsigned char *, b->fbuf);
size_t nbytes = b->flen;
sig_t osigpipe;
continue;
nsz = nbytes;
urv = uncompressbuf(fd, ms->bytes_max, i, buf, &newbuf, &nsz);
- DPRINTF("uncompressbuf = %d, %s, %zu\n", urv, (char *)newbuf,
- nsz);
+ DPRINTF("uncompressbuf = %d, %s, %" SIZE_T_FORMAT "u\n", urv,
+ (char *)newbuf, nsz);
switch (urv) {
case OKDATA:
case ERRDATA:
}
closefd(fdp[STDIN_FILENO], 0);
- DPRINTF("Returning %p n=%zu rv=%d\n", *newch, *n, rv);
+ DPRINTF("Returning %p n=%" SIZE_T_FORMAT "u rv=%d\n", *newch, *n, rv);
return rv;
}
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: der.c,v 1.14 2018/09/09 20:33:28 christos Exp $")
+FILE_RCSID("@(#)$File: der.c,v 1.15 2018/10/15 16:29:16 christos Exp $")
#endif
#endif
if (gettag(b, &offs, len) == DER_BAD)
return -1;
- DPRINTF(("%s1: %d %zu %u\n", __func__, ms->offset, offs, m->offset));
+ DPRINTF(("%s1: %d %" SIZE_T_FORMAT "u %u\n", __func__, ms->offset,
+ offs, m->offset));
uint32_t tlen = getlength(b, &offs, len);
if (tlen == DER_BAD)
return -1;
- DPRINTF(("%s2: %d %zu %u\n", __func__, ms->offset, offs, tlen));
+ DPRINTF(("%s2: %d %" SIZE_T_FORMAT "u %u\n", __func__, ms->offset,
+ offs, tlen));
offs += ms->offset + m->offset;
DPRINTF(("cont_level = %d\n", m->cont_level));
#ifdef DEBUG_DER
for (size_t i = 0; i < m->cont_level; i++)
- printf("cont_level[%zu] = %u\n", i, ms->c.li[i].off);
+ printf("cont_level[%" SIZE_T_FORMAT "u] = %u\n", i,
+ ms->c.li[i].off);
#endif
if (m->cont_level != 0) {
if (offs + tlen > nbytes)
slen = slen * 10 + *s - '0';
while (isdigit((unsigned char)*++s));
if ((ms->flags & MAGIC_DEBUG) != 0)
- fprintf(stderr, "%s: len %zu %u\n", __func__,
- slen, tlen);
+ fprintf(stderr, "%s: len %" SIZE_T_FORMAT "u %u\n",
+ __func__, slen, tlen);
if (tlen != slen)
return 0;
goto again;
}
val:
- DPRINTF(("%s: before data %zu %u\n", __func__, offs, tlen));
+ DPRINTF(("%s: before data %" SIZE_T_FORMAT "u %u\n", __func__, offs,
+ tlen));
der_data(buf, sizeof(buf), tag, b + offs, tlen);
if ((ms->flags & MAGIC_DEBUG) != 0)
fprintf(stderr, "%s: data %s %s\n", __func__, buf, s);
break;
uint32_t len = getlength(p, &x, ep - p + x);
- printf("%zu %zu-%zu %c,%c,%s,%u:", level, ox, x,
+ printf("%" SIZE_T_FORMAT "u %" SIZE_T_FORMAT "u-%"
+ SIZE_T_FORMAT "u %c,%c,%s,%u:", level, ox, x,
der_class[c], der_type[t],
der_tag(buf, sizeof(buf), tag), len);
q = p + x;
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: encoding.c,v 1.14 2017/11/02 20:25:39 christos Exp $")
+FILE_RCSID("@(#)$File: encoding.c,v 1.15 2018/10/15 16:29:16 christos Exp $")
#endif /* lint */
#include "magic.h"
file_encoding(struct magic_set *ms, const struct buffer *b, unichar **ubuf,
size_t *ulen, const char **code, const char **code_mime, const char **type)
{
- const unsigned char *buf = b->fbuf;
+ const unsigned char *buf = CAST(const unsigned char *, b->fbuf);
size_t nbytes = b->flen;
size_t mlen;
int rv = 1, ucs_type;
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.198 2018/10/01 18:45:39 christos Exp $
+ * @(#)$File: file.h,v 1.199 2018/10/15 16:29:16 christos Exp $
*/
#ifndef __file_h__
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
#endif
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
#ifdef WIN32
#ifdef _WIN64
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: is_json.c,v 1.10 2018/09/09 20:33:28 christos Exp $")
+FILE_RCSID("@(#)$File: is_json.c,v 1.11 2018/10/15 16:29:16 christos Exp $")
#endif
#include <string.h>
int
file_is_json(struct magic_set *ms, const struct buffer *b)
{
- const unsigned char *uc = b->fbuf;
+ const unsigned char *uc = CAST(const unsigned char *, b->fbuf);
const unsigned char *ue = uc + b->flen;
size_t st[JSON_MAX];
int mime = ms->flags & MAGIC_MIME;
return -1;
#if JSON_COUNT
#define P(n) st[n], st[n] > 1 ? "s" : ""
- if (file_printf(ms, " (%zu object%s, %zu array%s, %zu string%s, "
- "%zu constant%s, %zu number%s)", P(JSON_OBJECT), P(JSON_ARRAY),
- P(JSON_STRING), P(JSON_CONSTANT), P(JSON_NUMBER)) == -1)
+ if (file_printf(ms, " (%" SIZE_T_FORMAT "u object%s, %" SIZE_T_FORMAT
+ "u array%s, %" SIZE_T_FORMAT "u string%s, %" SIZE_T_FORMAT
+ "u constant%s, %" SIZE_T_FORMAT "u number%s)", P(JSON_OBJECT),
+ P(JSON_ARRAY), P(JSON_STRING), P(JSON_CONSTANT), P(JSON_NUMBER))
+ == -1)
return -1;
#endif
return 1;
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: is_tar.c,v 1.42 2018/08/01 08:50:20 christos Exp $")
+FILE_RCSID("@(#)$File: is_tar.c,v 1.43 2018/10/15 16:29:16 christos Exp $")
#endif
#include "magic.h"
protected int
file_is_tar(struct magic_set *ms, const struct buffer *b)
{
- const unsigned char *buf = b->fbuf;
+ const unsigned char *buf = CAST(const unsigned char *, b->fbuf);
size_t nbytes = b->flen;
/*
* Do the tar test first, because if the first file in the tar
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.70 2018/09/09 20:33:28 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.71 2018/10/15 16:29:16 christos Exp $")
#endif
#include <assert.h>
file_trycdf(struct magic_set *ms, const struct buffer *b)
{
int fd = b->fd;
- const unsigned char *buf = b->fbuf;
+ const unsigned char *buf = CAST(const unsigned char *, b->fbuf);
size_t nbytes = b->flen;
cdf_info_t info;
cdf_header_t h;
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.153 2018/09/11 00:37:33 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.154 2018/10/15 16:29:16 christos Exp $")
#endif
#ifdef BUILTIN_ELF
if (file_printf(ms, ", from '%.31s', pid=%u, uid=%u, "
"gid=%u, nlwps=%u, lwp=%u (signal %u/code %u)",
file_printable(sbuf, sizeof(sbuf),
- CAST(char *, pi.cpi_name)),
+ RCAST(char *, pi.cpi_name)),
elf_getu32(swap, (uint32_t)pi.cpi_pid),
elf_getu32(swap, pi.cpi_euid),
elf_getu32(swap, pi.cpi_egid),
return offset;
}
- if (namesz == 7 && strcmp(CAST(char *, &nbuf[noff]), "NetBSD") == 0) {
+ if (namesz == 7 && strcmp(RCAST(char *, &nbuf[noff]), "NetBSD") == 0) {
int descw, flag;
const char *str, *tag;
if (descsz > 100)
if (*flags & flag)
return offset;
- str = CAST(const char *, &nbuf[doff]);
+ str = RCAST(const char *, &nbuf[doff]);
descw = CAST(int, descsz);
*flags |= flag;
file_printf(ms, ", %s: %.*s", tag, descw, str);
file_tryelf(struct magic_set *ms, const struct buffer *b)
{
int fd = b->fd;
- const unsigned char *buf = b->fbuf;
+ const unsigned char *buf = CAST(const unsigned char *, b->fbuf);
size_t nbytes = b->flen;
union {
int32_t l;
* file locations and thus file(1) cannot determine it from easily.
* Instead we traverse thru all section headers until a symbol table
* one is found or else the binary is stripped.
- * Return immediately if it's not ELF (so we avoid pipe2file unless needed).
+ * Return immediately if it's not ELF (so we avoid pipe2file unless
+ * needed).
*/
if (buf[EI_MAG0] != ELFMAG0
|| (buf[EI_MAG1] != ELFMAG1 && buf[EI_MAG1] != OLFMAG1)
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.270 2018/09/09 20:33:28 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.271 2018/10/15 16:29:16 christos Exp $")
#endif /* lint */
#include "magic.h"
ms->line = m->lineno;
/* if main entry matches, print it... */
- switch (mget(ms, m, b, bb.fbuf, bb.flen, offset, cont_level,
+ switch (mget(ms, m, b, CAST(const unsigned char *, bb.fbuf),
+ bb.flen, offset, cont_level,
mode, text, flip, indir_count, name_count,
printed_something, need_separator, returnval)) {
case -1:
continue;
}
#endif
- switch (mget(ms, m, b, bb.fbuf, bb.flen, offset,
+ switch (mget(ms, m, b, CAST(const unsigned char *,
+ bb.fbuf), bb.flen, offset,
cont_level, mode, text, flip, indir_count,
name_count, printed_something, need_separator,
returnval)) {
if (o == -1 || (size_t)o > nbytes) {
if ((ms->flags & MAGIC_DEBUG) != 0) {
(void)fprintf(stderr,
- "Bad DER offset %d nbytes=%zu",
- o, nbytes);
+ "Bad DER offset %d nbytes=%"
+ SIZE_T_FORMAT "u", o, nbytes);
}
*op = 0;
return 0;
if ((size_t)o > nbytes) {
#if 0
- file_error(ms, 0, "Offset out of range %zu > %zu",
- (size_t)o, nbytes);
+ file_error(ms, 0, "Offset out of range %" SIZE_T_FORMAT
+ "u > %" SIZE_T_FORMAT "u", (size_t)o, nbytes);
#endif
return -1;
}
return -1;
if (o != 0) {
// Not yet!
- file_magerror(ms, "non zero offset %zu at"
- " level %u", o, cont_level);
+ file_magerror(ms, "non zero offset %" SIZE_T_FORMAT
+ "u at level %u", o, cont_level);
return -1;
}
if ((size_t)-m->offset > b->elen)
}
}
if ((ms->flags & MAGIC_DEBUG) != 0) {
- fprintf(stderr, "bb=[%p,%zu], %d [b=%p,%zu], [o=%#x, c=%d]\n",
+ fprintf(stderr, "bb=[%p,%" SIZE_T_FORMAT "u], %d [b=%p,%"
+ SIZE_T_FORMAT "u], [o=%#x, c=%d]\n",
bb->fbuf, bb->flen, ms->offset, b->fbuf, b->flen,
m->offset, cont_level);
}