]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
endian: check byte order on OSX
authorNoah Watkins <noahwatkins@gmail.com>
Thu, 2 Jan 2014 18:45:41 +0000 (10:45 -0800)
committerNoah Watkins <noahwatkins@gmail.com>
Thu, 2 Jan 2014 19:03:39 +0000 (11:03 -0800)
Defines CEPH_[BIG|LITTLE]_ENDIAN to use, as BYTE_ORDER etc macros may be
different names on different platforms.

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
src/common/sctp_crc32.c
src/include/byteorder.h

index c02ed856dbd78abf8e9881837fba4761237d7f9a..4acf5298510ab871e897f74ec775de2bde0a383a 100644 (file)
@@ -42,11 +42,7 @@ __FBSDID("$FreeBSD: src/sys/netinet/sctp_crc32.c,v 1.8 2007/05/08 17:01:10 rrs E
 
 #include <stdint.h>
 
-#if defined(__FreeBSD__)
-#include <sys/endian.h>
-#else
-#include <endian.h>
-#endif
+#include "include/byteorder.h"
 
 #ifndef SCTP_USE_ADLER32
 
@@ -541,7 +537,7 @@ sctp_crc32c_sb8_64_bit(uint32_t crc,
                crc = sctp_crc_tableil8_o32[(crc ^ *p_buf++) & 0x000000FF] ^
                    (crc >> 8);
        for (li = 0; li < running_length / 8; li++) {
-#if BYTE_ORDER == BIG_ENDIAN
+#ifdef CEPH_BIG_ENDIAN
                crc ^= *p_buf++;
                crc ^= (*p_buf++) << 8;
                crc ^= (*p_buf++) << 16;
@@ -557,7 +553,7 @@ sctp_crc32c_sb8_64_bit(uint32_t crc,
                    sctp_crc_tableil8_o72[term2 & 0x000000FF] ^
                    sctp_crc_tableil8_o64[(term2 >> 8) & 0x000000FF];
 
-#if BYTE_ORDER == BIG_ENDIAN
+#ifdef CEPH_BIG_ENDIAN
                crc ^= sctp_crc_tableil8_o56[*p_buf++];
                crc ^= sctp_crc_tableil8_o48[*p_buf++];
                crc ^= sctp_crc_tableil8_o40[*p_buf++];
@@ -610,7 +606,7 @@ sctp_crc32c_sb8_64_bit_zero(uint32_t crc,
                    sctp_crc_tableil8_o72[term2 & 0x000000FF] ^
                    sctp_crc_tableil8_o64[(term2 >> 8) & 0x000000FF];
 
-#if BYTE_ORDER == BIG_ENDIAN
+#ifdef CEPH_BIG_ENDIAN
                crc ^= sctp_crc_tableil8_o56[0];
                crc ^= sctp_crc_tableil8_o48[0];
                crc ^= sctp_crc_tableil8_o40[0];
index f8c74991e7ab35c4d41d42901139808415213fbc..191d24256db9941c237a0044a9ea0cafd46bf2e7 100644 (file)
@@ -7,18 +7,31 @@
 #ifndef CEPH_BYTEORDER_H
 #define CEPH_BYTEORDER_H
 
-#if defined(__linux__)
-#include <endian.h>
-#elif defined(__FreeBSD__)
-#include <sys/endian.h>
-#else
-#error "Your platform is not yet supported."
+#include <sys/param.h>
+#include "int_types.h"
+
+#if defined(__APPLE__)
+# if __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN
+#  define CEPH_LITTLE_ENDIAN
+# elif __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN
+#  define CEPH_BIG_ENDIAN
+# endif
 #endif
 
 #if defined(__FreeBSD__)
-#define        __BYTE_ORDER _BYTE_ORDER
-#define        __BIG_ENDIAN _BIG_ENDIAN
-#define        __LITTLE_ENDIAN _LITTLE_ENDIAN
+# if _BYTE_ORDER == _LITTLE_ENDIAN
+#  define CEPH_LITTLE_ENDIAN
+# elif _BYTE_ORDER == _BIG_ENDIAN
+#  define CEPH_BIG_ENDIAN
+# endif
+#endif
+
+#if defined(__linux__)
+# if BYTE_ORDER == LITTLE_ENDIAN
+#  define CEPH_LITTLE_ENDIAN
+# elif BYTE_ORDER == BIG_ENDIAN
+#  define CEPH_BIG_ENDIAN
+# endif
 #endif
 
 static __inline__ __u16 swab16(__u16 val) 
@@ -44,24 +57,20 @@ static __inline__ uint64_t swab64(uint64_t val)
          ((val << 56)));
 }
 
-#if !defined(__BYTE_ORDER) || !defined(__BIG_ENDIAN) || !defined(__LITTLE_ENDIAN)
-#error "Endianess is unknown!"
-#endif
-
 // mswab == maybe swab (if not LE)
-#if __BYTE_ORDER == __BIG_ENDIAN
+#ifdef CEPH_BIG_ENDIAN
 # define mswab64(a) swab64(a)
 # define mswab32(a) swab32(a)
 # define mswab16(a) swab16(a)
-#else
-# if __BYTE_ORDER != __LITTLE_ENDIAN
-#  warning __BYTE_ORDER is not defined, assuming little endian
-# endif
+#elif defined(CEPH_LITTLE_ENDIAN)
 # define mswab64(a) (a)
 # define mswab32(a) (a)
 # define mswab16(a) (a)
+#else
+# error "Could not determine endianess"
 #endif
 
+#ifdef __cplusplus
 
 #define MAKE_LE_CLASS(bits)                                            \
   struct ceph_le##bits {                                                       \
@@ -81,6 +90,8 @@ MAKE_LE_CLASS(32)
 MAKE_LE_CLASS(16)
 #undef MAKE_LE_CLASS
 
+#endif /* __cplusplus */
+
 #define init_le64(x) { (__u64)mswab64(x) }
 #define init_le32(x) { (__u32)mswab32(x) }
 #define init_le16(x) { (__u16)mswab16(x) }