summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt8
-rw-r--r--configure.ac2
-rw-r--r--librabbitmq/amqp_private.h39
3 files changed, 45 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 065f5db..9e93517 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -137,8 +137,10 @@ mark_as_advanced(AMQP_CODEGEN_DIR)
include(CheckFunctionExists)
include(CheckLibraryExists)
+include(CMakePushCheckState)
# Detect if we need to link against a socket library:
+cmake_push_check_state()
if (WIN32)
# Always use WinSock2 on Windows
set(SOCKET_LIBRARIES ws2_32)
@@ -175,6 +177,12 @@ else ()
endif ()
endif ()
endif ()
+cmake_pop_check_state()
+
+cmake_push_check_state()
+set(CMAKE_REQUIRED_LIBRARIES ${SOCKET_LIBRARIES})
+check_function_exists(htonll HAVE_HTONLL)
+cmake_pop_check_state()
find_package(POPT)
find_package(XmlTo)
diff --git a/configure.ac b/configure.ac
index 117c3a6..985ca18 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,7 +36,6 @@ m4_ifdef([AC_PROG_CC_C99], [AC_PROG_CC_C99],
# Environment setup
AC_CANONICAL_HOST
-AC_C_BIGENDIAN
AC_C_INLINE
# Set compiler flags
@@ -96,6 +95,7 @@ AC_SEARCH_LIBS([socket], [socket], [],
[LIBS="-lsocket -lnsl $LIBS"],
[AC_MSG_ERROR([cannot find socket library (library with socket symbol)])],
[-lnsl])])
+AC_CHECK_FUNCS([htonll])
# 64-bit option
AC_ARG_ENABLE([64-bit],
diff --git a/librabbitmq/amqp_private.h b/librabbitmq/amqp_private.h
index bbee792..fb01d12 100644
--- a/librabbitmq/amqp_private.h
+++ b/librabbitmq/amqp_private.h
@@ -206,7 +206,38 @@ static inline int amqp_decode_##bits(amqp_bytes_t encoded, size_t *offset, \
} \
}
-#ifndef WORDS_BIGENDIAN
+/* Determine byte order */
+#if defined(__GLIBC__)
+# include <endian.h>
+# if (__BYTE_ORDER == __LITTLE_ENDIAN)
+# define AMQP_LITTLE_ENDIAN
+# elif (__BYTE_ORDER == __BIG_ENDIAN)
+# define AMQP_BIG_ENDIAN
+# else
+ /* Don't define anything */
+# endif
+#elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) || \
+ defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
+# define AMQP_BIG_ENDIAN
+#elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) || \
+ defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
+# define AMQP_LITTLE_ENDIAN
+#elif defined(__hppa__) || defined(__HPPA__) || defined(__hppa) || \
+ defined(_POWER) || defined(__powerpc__) || defined(__ppc___) || \
+ defined(_MIPSEB) || defined(__s390__) || \
+ defined(__sparc) || defined(__sparc__)
+# define AMQP_BIG_ENDIAN
+#elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) || \
+ defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || \
+ defined(__ia64) || defined(__ia64__) || defined(_M_IA64) || \
+ defined(__arm__) || defined(_M_ARM) || \
+ defined(__i386__) || defined(_M_IX86)
+# define AMQP_LITTLE_ENDIAN
+#else
+ /* Don't define anything */
+#endif
+
+#if defined(AMQP_LITTLE_ENDIAN)
#define DECLARE_XTOXLL(func) \
static inline uint64_t func##ll(uint64_t val) \
@@ -223,7 +254,7 @@ static inline uint64_t func##ll(uint64_t val) \
return u.whole; \
}
-#else
+#elif defined(AMQP_BIG_ENDIAN)
#define DECLARE_XTOXLL(func) \
static inline uint64_t func##ll(uint64_t val) \
@@ -238,9 +269,11 @@ static inline uint64_t func##ll(uint64_t val) \
return u.whole; \
}
+#else
+# error Endianness not known
#endif
-#ifndef __sun
+#ifndef HAVE_HTONLL
DECLARE_XTOXLL(hton)
DECLARE_XTOXLL(ntoh)
#endif