Use endian.h and byteswap.h.
authorBastian Blank <waldi@debian.org>
Thu, 29 Sep 2005 12:55:36 +0000 (12:55 +0000)
committerBastian Blank <waldi@debian.org>
Thu, 29 Sep 2005 12:55:36 +0000 (12:55 +0000)
kpartx/byteorder.h

index 0f6ade1..6d2588b 100644 (file)
@@ -1,15 +1,19 @@
 #ifndef BYTEORDER_H_INCLUDED
 #define BYTEORDER_H_INCLUDED
 
-#if defined (__s390__) || defined (__s390x__)
-#define le32_to_cpu(x) ( \
-               (*(((unsigned char *) &(x)))) + \
-               (*(((unsigned char *) &(x))+1) << 8) + \
-               (*(((unsigned char *) &(x))+2) << 16) + \
-               (*(((unsigned char *) &(x))+3) << 24) \
-       )
+#ifdef __linux__
+#  include <endian.h>
+#  include <byteswap.h>
 #else
-#define le32_to_cpu(x) (x)
+#  error unsupported
+#endif
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+#  define le32_to_cpu(x) (x)
+#elif BYTE_ORDER == BIG_ENDIAN
+#  define le32_to_cpu(x) bswap_32(x)
+#else
+#  error unsupported
 #endif
 
 #endif                         /* BYTEORDER_H_INCLUDED */