summaryrefslogtreecommitdiffstats
path: root/usr.sbin/crunch
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2003-01-29 08:37:26 +0000
committerru <ru@FreeBSD.org>2003-01-29 08:37:26 +0000
commit749b58d851d0be04e12509e776406b62f6da56e3 (patch)
treec93ab1ecd58e80c0583be5837ff01ce2206d767f /usr.sbin/crunch
parentcd45eb4961efd72b56900a16daa14ae76d9c1966 (diff)
downloadFreeBSD-src-749b58d851d0be04e12509e776406b62f6da56e3.zip
FreeBSD-src-749b58d851d0be04e12509e776406b62f6da56e3.tar.gz
Part 1/3 of unbreaking cross releases:
Back out the removal of custom version of endian.h system header. On recent systems, it just falls back to <sys/endian.h>. But on older systems like 5.0-DP1 or 4-STABLE, this private version may be necessary, as crunchide(1) is a cross-tool for "make release". Spotted by: kris, markm
Diffstat (limited to 'usr.sbin/crunch')
-rw-r--r--usr.sbin/crunch/crunchide/endian.h57
-rw-r--r--usr.sbin/crunch/crunchide/exec_elf32.c2
2 files changed, 58 insertions, 1 deletions
diff --git a/usr.sbin/crunch/crunchide/endian.h b/usr.sbin/crunch/crunchide/endian.h
new file mode 100644
index 0000000..2234f78
--- /dev/null
+++ b/usr.sbin/crunch/crunchide/endian.h
@@ -0,0 +1,57 @@
+/*
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+
+#if __FreeBSD_version >= 500034
+#include <sys/endian.h>
+#else
+#include <machine/endian.h>
+
+#define bswap16(x) (uint16_t) \
+ ((x >> 8) | (x << 8))
+
+#define bswap32(x) (uint32_t) \
+ ((x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24))
+
+#define bswap64(x) (uint64_t) \
+ ((x >> 56) | ((x >> 40) & 0xff00) | ((x >> 24) & 0xff0000) | \
+ ((x >> 8) & 0xff000000) | ((x << 8) & ((uint64_t)0xff << 32)) | \
+ ((x << 24) & ((uint64_t)0xff << 40)) | \
+ ((x << 40) & ((uint64_t)0xff << 48)) | ((x << 56)))
+
+/*
+ * Host to big endian, host to little endian, big endian to host, and little
+ * endian to host byte order functions as detailed in byteorder(9).
+ */
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+#define htobe16(x) bswap16((uint16_t)(x))
+#define htobe32(x) bswap32((uint32_t)(x))
+#define htobe64(x) bswap64((uint64_t)(x))
+#define htole16(x) ((uint16_t)(x))
+#define htole32(x) ((uint32_t)(x))
+#define htole64(x) ((uint64_t)(x))
+
+#define be16toh(x) bswap16((uint16_t)(x))
+#define be32toh(x) bswap32((uint32_t)(x))
+#define be64toh(x) bswap64((uint64_t)(x))
+#define le16toh(x) ((uint16_t)(x))
+#define le32toh(x) ((uint32_t)(x))
+#define le64toh(x) ((uint64_t)(x))
+#else /* _BYTE_ORDER != _LITTLE_ENDIAN */
+#define htobe16(x) ((uint16_t)(x))
+#define htobe32(x) ((uint32_t)(x))
+#define htobe64(x) ((uint64_t)(x))
+#define htole16(x) bswap16((uint16_t)(x))
+#define htole32(x) bswap32((uint32_t)(x))
+#define htole64(x) bswap64((uint64_t)(x))
+
+#define be16toh(x) ((uint16_t)(x))
+#define be32toh(x) ((uint32_t)(x))
+#define be64toh(x) ((uint64_t)(x))
+#define le16toh(x) bswap16((uint16_t)(x))
+#define le32toh(x) bswap32((uint32_t)(x))
+#define le64toh(x) bswap64((uint64_t)(x))
+#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
+#endif
diff --git a/usr.sbin/crunch/crunchide/exec_elf32.c b/usr.sbin/crunch/crunchide/exec_elf32.c
index 25ca2b4..d21fc12 100644
--- a/usr.sbin/crunch/crunchide/exec_elf32.c
+++ b/usr.sbin/crunch/crunchide/exec_elf32.c
@@ -41,7 +41,6 @@ __FBSDID("$FreeBSD$");
#endif
#include <sys/types.h>
-#include <sys/endian.h>
#include <sys/stat.h>
#include <errno.h>
@@ -50,6 +49,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <unistd.h>
+#include "endian.h"
#include "extern.h"
#if (defined(NLIST_ELF32) && (ELFSIZE == 32)) || \
OpenPOWER on IntegriCloud