summaryrefslogtreecommitdiff
path: root/src/softmagic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/softmagic.c')
-rw-r--r--src/softmagic.c116
1 files changed, 48 insertions, 68 deletions
diff --git a/src/softmagic.c b/src/softmagic.c
index b5b680f3..891910c7 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -34,16 +34,15 @@
#ifndef lint
-FILE_RCSID("@(#)$Id: softmagic.c,v 1.50 2002/06/11 17:31:46 christos Exp $")
+FILE_RCSID("@(#)$Id: softmagic.c,v 1.51 2002/07/03 18:26:38 christos Exp $")
#endif /* lint */
-static int match __P((struct magic *, uint32, unsigned char *, int));
-static int mget __P((union VALUETYPE *,
- unsigned char *, struct magic *, int));
-static int mcheck __P((union VALUETYPE *, struct magic *));
-static int32 mprint __P((union VALUETYPE *, struct magic *));
-static void mdebug __P((int32, char *, int));
-static int mconvert __P((union VALUETYPE *, struct magic *));
+static int match(struct magic *, uint32_t, unsigned char *, int);
+static int mget(union VALUETYPE *, unsigned char *, struct magic *, int);
+static int mcheck(union VALUETYPE *, struct magic *);
+static int32_t mprint(union VALUETYPE *, struct magic *);
+static void mdebug(int32_t, char *, int);
+static int mconvert(union VALUETYPE *, struct magic *);
extern int kflag;
@@ -54,9 +53,7 @@ extern int kflag;
*/
/*ARGSUSED1*/ /* nbytes passed for regularity, maybe need later */
int
-softmagic(buf, nbytes)
- unsigned char *buf;
- int nbytes;
+softmagic(unsigned char *buf, int nbytes)
{
struct mlist *ml;
@@ -95,24 +92,20 @@ softmagic(buf, nbytes)
* so that higher-level continuations are processed.
*/
static int
-match(magic, nmagic, s, nbytes)
- struct magic *magic;
- uint32 nmagic;
- unsigned char *s;
- int nbytes;
+match(struct magic *magic, uint32_t nmagic, unsigned char *s, int nbytes)
{
int magindex = 0;
int cont_level = 0;
int need_separator = 0;
union VALUETYPE p;
- static int32 *tmpoff = NULL;
+ static int32_t *tmpoff = NULL;
static size_t tmplen = 0;
- int32 oldoff = 0;
+ int32_t oldoff = 0;
int returnval = 0; /* if a match is found it is set to 1*/
int firstline = 1; /* a flag to print X\n X\n- X */
if (tmpoff == NULL)
- if ((tmpoff = (int32 *) malloc(tmplen = 20)) == NULL)
+ if ((tmpoff = (int32_t *) malloc(tmplen = 20)) == NULL)
error("out of memory\n");
for (magindex = 0; magindex < nmagic; magindex++) {
@@ -143,7 +136,7 @@ match(magic, nmagic, s, nbytes)
need_separator = 1;
/* and any continuations that match */
if (++cont_level >= tmplen)
- if ((tmpoff = (int32 *) realloc(tmpoff,
+ if ((tmpoff = (int32_t *) realloc(tmpoff,
tmplen += 20)) == NULL)
error("out of memory\n");
while (magic[magindex+1].cont_level != 0 &&
@@ -190,7 +183,7 @@ match(magic, nmagic, s, nbytes)
*/
if (++cont_level >= tmplen)
if ((tmpoff =
- (int32 *) realloc(tmpoff,
+ (int32_t *) realloc(tmpoff,
tmplen += 20)) == NULL)
error("out of memory\n");
}
@@ -208,13 +201,11 @@ match(magic, nmagic, s, nbytes)
return returnval; /* This is hit if -k is set or there is no match */
}
-static int32
-mprint(p, m)
- union VALUETYPE *p;
- struct magic *m;
+static int32_t
+mprint(union VALUETYPE *p, struct magic *m)
{
- uint32 v;
- int32 t=0 ;
+ uint32_t v;
+ int32_t t=0 ;
switch (m->type) {
@@ -236,8 +227,8 @@ mprint(p, m)
case BELONG:
case LELONG:
v = signextend(m, p->l);
- (void) printf(m->desc, (uint32) v);
- t = m->offset + sizeof(int32);
+ (void) printf(m->desc, (uint32_t) v);
+ t = m->offset + sizeof(int32_t);
break;
case STRING:
@@ -288,9 +279,7 @@ mprint(p, m)
* (unless you have a better idea)
*/
static int
-mconvert(p, m)
- union VALUETYPE *p;
- struct magic *m;
+mconvert(union VALUETYPE *p, struct magic *m)
{
switch (m->type) {
case BYTE:
@@ -448,7 +437,7 @@ mconvert(p, m)
case BELONG:
case BEDATE:
case BELDATE:
- p->l = (int32)
+ p->l = (int32_t)
((p->hl[0]<<24)|(p->hl[1]<<16)|(p->hl[2]<<8)|(p->hl[3]));
if (m->mask)
switch (m->mask_op&0x7F) {
@@ -515,7 +504,7 @@ mconvert(p, m)
case LELONG:
case LEDATE:
case LELDATE:
- p->l = (int32)
+ p->l = (int32_t)
((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0]));
if (m->mask)
switch (m->mask_op&0x7F) {
@@ -557,10 +546,7 @@ mconvert(p, m)
static void
-mdebug(offset, str, len)
- int32 offset;
- char *str;
- int len;
+mdebug(int32_t offset, char *str, int len)
{
(void) fprintf(stderr, "mget @%d: ", offset);
showstr(stderr, (char *) str, len);
@@ -569,13 +555,9 @@ mdebug(offset, str, len)
}
static int
-mget(p, s, m, nbytes)
- union VALUETYPE* p;
- unsigned char *s;
- struct magic *m;
- int nbytes;
+mget(union VALUETYPE *p, unsigned char *s, struct magic *m, int nbytes)
{
- int32 offset = m->offset;
+ int32_t offset = m->offset;
if (m->type == REGEX) {
/*
@@ -595,7 +577,7 @@ mget(p, s, m, nbytes)
* the usefulness of padding with zeroes eludes me, it
* might even cause problems
*/
- int32 have = nbytes - offset;
+ int32_t have = nbytes - offset;
memset(p, 0, sizeof(union VALUETYPE));
if (have > 0)
memcpy(p, s + offset, have);
@@ -768,56 +750,56 @@ mget(p, s, m, nbytes)
if (m->in_offset)
switch (m->in_op&0x7F) {
case OPAND:
- offset = (int32)((p->hl[0]<<24)|
+ offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
(p->hl[3])) &
m->in_offset;
break;
case OPOR:
- offset = (int32)((p->hl[0]<<24)|
+ offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
(p->hl[3])) |
m->in_offset;
break;
case OPXOR:
- offset = (int32)((p->hl[0]<<24)|
+ offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
(p->hl[3])) ^
m->in_offset;
break;
case OPADD:
- offset = (int32)((p->hl[0]<<24)|
+ offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
(p->hl[3])) +
m->in_offset;
break;
case OPMINUS:
- offset = (int32)((p->hl[0]<<24)|
+ offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
(p->hl[3])) -
m->in_offset;
break;
case OPMULTIPLY:
- offset = (int32)((p->hl[0]<<24)|
+ offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
(p->hl[3])) *
m->in_offset;
break;
case OPDIVIDE:
- offset = (int32)((p->hl[0]<<24)|
+ offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
(p->hl[3])) /
m->in_offset;
break;
case OPMODULO:
- offset = (int32)((p->hl[0]<<24)|
+ offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
(p->hl[3])) %
@@ -831,56 +813,56 @@ mget(p, s, m, nbytes)
if (m->in_offset)
switch (m->in_op&0x7F) {
case OPAND:
- offset = (int32)((p->hl[3]<<24)|
+ offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
(p->hl[0])) &
m->in_offset;
break;
case OPOR:
- offset = (int32)((p->hl[3]<<24)|
+ offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
(p->hl[0])) |
m->in_offset;
break;
case OPXOR:
- offset = (int32)((p->hl[3]<<24)|
+ offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
(p->hl[0])) ^
m->in_offset;
break;
case OPADD:
- offset = (int32)((p->hl[3]<<24)|
+ offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
(p->hl[0])) +
m->in_offset;
break;
case OPMINUS:
- offset = (int32)((p->hl[3]<<24)|
+ offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
(p->hl[0])) -
m->in_offset;
break;
case OPMULTIPLY:
- offset = (int32)((p->hl[3]<<24)|
+ offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
(p->hl[0])) *
m->in_offset;
break;
case OPDIVIDE:
- offset = (int32)((p->hl[3]<<24)|
+ offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
(p->hl[0])) /
m->in_offset;
break;
case OPMODULO:
- offset = (int32)((p->hl[3]<<24)|
+ offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
(p->hl[0])) %
@@ -946,12 +928,10 @@ mget(p, s, m, nbytes)
}
static int
-mcheck(p, m)
- union VALUETYPE* p;
- struct magic *m;
+mcheck(union VALUETYPE *p, struct magic *m)
{
- uint32 l = m->value.l;
- uint32 v;
+ uint32_t l = m->value.l;
+ uint32_t v;
int matched;
if ( (m->value.s[0] == 'x') && (m->value.s[1] == '\0') ) {
@@ -1082,7 +1062,7 @@ mcheck(p, m)
v, l, matched);
}
else {
- matched = (int32) v > (int32) l;
+ matched = (int32_t) v > (int32_t) l;
if (debug)
(void) fprintf(stderr, "%d > %d = %d\n",
v, l, matched);
@@ -1097,7 +1077,7 @@ mcheck(p, m)
v, l, matched);
}
else {
- matched = (int32) v < (int32) l;
+ matched = (int32_t) v < (int32_t) l;
if (debug)
(void) fprintf(stderr, "%d < %d = %d\n",
v, l, matched);