summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Groffen2011-01-08 19:49:38 +0100
committerKarel Zak2011-01-17 15:34:45 +0100
commitaabe2441765c632bba697945491e3e0ac29ac886 (patch)
treebf7e34cc148a94f8d4a5d3fc5e090d9710a5043a
parentwall: add usage function (diff)
downloadkernel-qcow2-util-linux-aabe2441765c632bba697945491e3e0ac29ac886.tar.gz
kernel-qcow2-util-linux-aabe2441765c632bba697945491e3e0ac29ac886.tar.xz
kernel-qcow2-util-linux-aabe2441765c632bba697945491e3e0ac29ac886.zip
build-sys: use WORDS_BIGENDIAN to determine platform byte-order
Autoconf contains the right magic to determine the endianness on many platforms next to Linux. This reverses previous commits to move away from WORDS_BIGENDIAN: "use __BYTE_ORDER rather than AC specific WORDS_BIGENDIAN" This is necessary to compile on non Linux platforms like Darwin and Solaris. Signed-off-by: Fabian Groffen <grobian@gentoo.org>
-rw-r--r--include/bitops.h11
-rw-r--r--lib/md5.c7
-rw-r--r--sys-utils/lscpu.c4
-rw-r--r--tests/helpers/test_sysinfo.c7
4 files changed, 6 insertions, 23 deletions
diff --git a/include/bitops.h b/include/bitops.h
index e283b8355..80d6f6f07 100644
--- a/include/bitops.h
+++ b/include/bitops.h
@@ -2,7 +2,6 @@
#define BITOPS_H
#include <stdint.h>
-#include <endian.h>
/*
* Bit map related macros. Usually provided by libc.
@@ -20,10 +19,6 @@
# define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
#endif
-#if !defined __BYTE_ORDER || !(__BYTE_ORDER == __LITTLE_ENDIAN) && !(__BYTE_ORDER == __BIG_ENDIAN)
-#error missing __BYTE_ORDER
-#endif
-
/*
* Byte swab macros (based on linux/byteorder/swab.h)
*/
@@ -51,7 +46,7 @@
(uint64_t)(((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56) ))
-#if (__BYTE_ORDER == __BIG_ENDIAN)
+#ifdef WORDS_BIGENDIAN
#define cpu_to_le16(x) swab16(x)
#define cpu_to_le32(x) swab32(x)
@@ -67,7 +62,7 @@
#define be32_to_cpu(x) (x)
#define be64_to_cpu(x) (x)
-#else /* __BYTE_ORDER != __BIG_ENDIAN */
+#else /* !WORDS_BIGENDIAN */
#define cpu_to_le16(x) (x)
#define cpu_to_le32(x) (x)
@@ -83,7 +78,7 @@
#define be32_to_cpu(x) swab32(x)
#define be64_to_cpu(x) swab64(x)
-#endif /* __BYTE_ORDER */
+#endif /* WORDS_BIGENDIAN */
#endif /* BITOPS_H */
diff --git a/lib/md5.c b/lib/md5.c
index 6ad4b6845..071630f19 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -14,16 +14,11 @@
* needed on buffers full of bytes, and then call MD5Final, which
* will fill a supplied 16-byte array with the digest.
*/
-#include <endian.h>
#include <string.h> /* for memcpy() */
#include "md5.h"
-#if !defined __BYTE_ORDER || !(__BYTE_ORDER == __LITTLE_ENDIAN) && !(__BYTE_ORDER == __BIG_ENDIAN)
-#error missing __BYTE_ORDER
-#endif
-
-#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+#if !defined(WORDS_BIGENDIAN)
#define byteReverse(buf, len) /* Nothing */
#else
void byteReverse(unsigned char *buf, unsigned longs);
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 224d5f99b..16e6b9a1e 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -818,13 +818,11 @@ print_readable(struct lscpu_desc *desc, int hex)
*(p - 2) = '\0';
print_s(_("CPU op-mode(s):"), buf);
}
-#ifdef __BYTE_ORDER
-#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+#if !defined(WORDS_BIGENDIAN)
print_s(_("Byte Order:"), "Little Endian");
#else
print_s(_("Byte Order:"), "Big Endian");
#endif
-#endif
print_n(_("CPU(s):"), desc->ncpus);
if (desc->online)
diff --git a/tests/helpers/test_sysinfo.c b/tests/helpers/test_sysinfo.c
index 9c841dbf8..cb7b66b1a 100644
--- a/tests/helpers/test_sysinfo.c
+++ b/tests/helpers/test_sysinfo.c
@@ -18,13 +18,8 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <endian.h>
#include <limits.h>
-#if !defined __BYTE_ORDER || !(__BYTE_ORDER == __LITTLE_ENDIAN) && !(__BYTE_ORDER == __BIG_ENDIAN)
-#error missing __BYTE_ORDER
-#endif
-
typedef struct {
const char *name;
int (*fnc)(void);
@@ -40,7 +35,7 @@ hlp_wordsize(void)
int
hlp_endianness(void)
{
-#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+#if !defined(WORDS_BIGENDIAN)
printf("LE\n");
#else
printf("BE\n");