169 lines
3.3 KiB
Diff
169 lines
3.3 KiB
Diff
---
|
|
src/apprentice.c | 70 ++++---------------------------------------------------
|
|
src/cdf.c | 54 +++---------------------------------------
|
|
2 files changed, 10 insertions(+), 114 deletions(-)
|
|
|
|
--- src/apprentice.c
|
|
+++ src/apprentice.c 2016-04-18 11:44:13.254519084 +0000
|
|
@@ -54,6 +54,7 @@ FILE_RCSID("@(#)$File: apprentice.c,v 1.
|
|
#if defined(HAVE_LIMITS_H)
|
|
#include <limits.h>
|
|
#endif
|
|
+#include <byteswap.h>
|
|
|
|
#ifndef SSIZE_MAX
|
|
#define MAXMAGIC_SIZE ((ssize_t)0x7fffffff)
|
|
@@ -132,9 +133,11 @@ private struct mlist *mlist_alloc(void);
|
|
private void mlist_free(struct mlist *);
|
|
private void byteswap(struct magic *, uint32_t);
|
|
private void bs1(struct magic *);
|
|
-private uint16_t swap2(uint16_t);
|
|
-private uint32_t swap4(uint32_t);
|
|
-private uint64_t swap8(uint64_t);
|
|
+
|
|
+#define swap2(x) bswap_16(x)
|
|
+#define swap4(x) bswap_32(x)
|
|
+#define swap8(x) bswap_64(x)
|
|
+
|
|
private char *mkdbname(struct magic_set *, const char *, int);
|
|
private struct magic_map *apprentice_buf(struct magic_set *, struct magic *,
|
|
size_t);
|
|
@@ -3175,67 +3178,6 @@ byteswap(struct magic *magic, uint32_t n
|
|
}
|
|
|
|
/*
|
|
- * swap a short
|
|
- */
|
|
-private uint16_t
|
|
-swap2(uint16_t sv)
|
|
-{
|
|
- uint16_t rv;
|
|
- uint8_t *s = (uint8_t *)(void *)&sv;
|
|
- uint8_t *d = (uint8_t *)(void *)&rv;
|
|
- d[0] = s[1];
|
|
- d[1] = s[0];
|
|
- return rv;
|
|
-}
|
|
-
|
|
-/*
|
|
- * swap an int
|
|
- */
|
|
-private uint32_t
|
|
-swap4(uint32_t sv)
|
|
-{
|
|
- uint32_t rv;
|
|
- uint8_t *s = (uint8_t *)(void *)&sv;
|
|
- uint8_t *d = (uint8_t *)(void *)&rv;
|
|
- d[0] = s[3];
|
|
- d[1] = s[2];
|
|
- d[2] = s[1];
|
|
- d[3] = s[0];
|
|
- return rv;
|
|
-}
|
|
-
|
|
-/*
|
|
- * swap a quad
|
|
- */
|
|
-private uint64_t
|
|
-swap8(uint64_t sv)
|
|
-{
|
|
- uint64_t rv;
|
|
- uint8_t *s = (uint8_t *)(void *)&sv;
|
|
- uint8_t *d = (uint8_t *)(void *)&rv;
|
|
-#if 0
|
|
- d[0] = s[3];
|
|
- d[1] = s[2];
|
|
- d[2] = s[1];
|
|
- d[3] = s[0];
|
|
- d[4] = s[7];
|
|
- d[5] = s[6];
|
|
- d[6] = s[5];
|
|
- d[7] = s[4];
|
|
-#else
|
|
- d[0] = s[7];
|
|
- d[1] = s[6];
|
|
- d[2] = s[5];
|
|
- d[3] = s[4];
|
|
- d[4] = s[3];
|
|
- d[5] = s[2];
|
|
- d[6] = s[1];
|
|
- d[7] = s[0];
|
|
-#endif
|
|
- return rv;
|
|
-}
|
|
-
|
|
-/*
|
|
* byteswap a single magic entry
|
|
*/
|
|
private void
|
|
--- src/cdf.c
|
|
+++ src/cdf.c 2016-04-18 11:44:13.254519084 +0000
|
|
@@ -50,6 +50,7 @@ FILE_RCSID("@(#)$File: cdf.c,v 1.76 2015
|
|
#ifdef HAVE_LIMITS_H
|
|
#include <limits.h>
|
|
#endif
|
|
+#include <byteswap.h>
|
|
|
|
#ifndef EFTYPE
|
|
#define EFTYPE EINVAL
|
|
@@ -80,56 +81,9 @@ static union {
|
|
CDF_TOLE8(CAST(uint64_t, x))))
|
|
#define CDF_GETUINT32(x, y) cdf_getuint32(x, y)
|
|
|
|
-
|
|
-/*
|
|
- * swap a short
|
|
- */
|
|
-static uint16_t
|
|
-_cdf_tole2(uint16_t sv)
|
|
-{
|
|
- uint16_t rv;
|
|
- uint8_t *s = (uint8_t *)(void *)&sv;
|
|
- uint8_t *d = (uint8_t *)(void *)&rv;
|
|
- d[0] = s[1];
|
|
- d[1] = s[0];
|
|
- return rv;
|
|
-}
|
|
-
|
|
-/*
|
|
- * swap an int
|
|
- */
|
|
-static uint32_t
|
|
-_cdf_tole4(uint32_t sv)
|
|
-{
|
|
- uint32_t rv;
|
|
- uint8_t *s = (uint8_t *)(void *)&sv;
|
|
- uint8_t *d = (uint8_t *)(void *)&rv;
|
|
- d[0] = s[3];
|
|
- d[1] = s[2];
|
|
- d[2] = s[1];
|
|
- d[3] = s[0];
|
|
- return rv;
|
|
-}
|
|
-
|
|
-/*
|
|
- * swap a quad
|
|
- */
|
|
-static uint64_t
|
|
-_cdf_tole8(uint64_t sv)
|
|
-{
|
|
- uint64_t rv;
|
|
- uint8_t *s = (uint8_t *)(void *)&sv;
|
|
- uint8_t *d = (uint8_t *)(void *)&rv;
|
|
- d[0] = s[7];
|
|
- d[1] = s[6];
|
|
- d[2] = s[5];
|
|
- d[3] = s[4];
|
|
- d[4] = s[3];
|
|
- d[5] = s[2];
|
|
- d[6] = s[1];
|
|
- d[7] = s[0];
|
|
- return rv;
|
|
-}
|
|
+#define _cdf_tole2(x) bswap_16(x)
|
|
+#define _cdf_tole4(x) bswap_32(x)
|
|
+#define _cdf_tole8(x) bswap_64(x)
|
|
|
|
/*
|
|
* grab a uint32_t from a possibly unaligned address, and return it in
|