THRIFT-851. php: php extension fails to compile on centos 5.x
This patch introduces an approach that is compatbile with both centos and Mac.
Patch: Todd Lipcon
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@986410 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/configure.ac b/configure.ac
index 7aaa433..412a223 100644
--- a/configure.ac
+++ b/configure.ac
@@ -145,7 +145,7 @@
AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_HEADERS([arpa/inet.h])
-AC_CHECK_HEADERS([endian.h])
+AC_CHECK_HEADERS([sys/param.h])
AC_CHECK_HEADERS([fcntl.h])
AC_CHECK_HEADERS([inttypes.h])
AC_CHECK_HEADERS([limits.h])
diff --git a/lib/cpp/src/protocol/TProtocol.h b/lib/cpp/src/protocol/TProtocol.h
index 7d7b065..2e24f75 100644
--- a/lib/cpp/src/protocol/TProtocol.h
+++ b/lib/cpp/src/protocol/TProtocol.h
@@ -76,8 +76,8 @@
using apache::thrift::transport::TTransport;
-#ifdef HAVE_ENDIAN_H
-#include <endian.h>
+#ifdef HAVE_SYS_PARAM_H_
+#include <sys/param.h>
#endif
#ifndef __BYTE_ORDER
diff --git a/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp b/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp
index 193669b..8348a97 100644
--- a/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp
+++ b/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp
@@ -24,13 +24,10 @@
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
-#include <machine/endian.h>
-#include <machine/byte_order.h>
+#include <sys/param.h>
#include <stdexcept>
-#ifndef _BYTESWAP_H
-#define _BYTESWAP_H
-
+#ifndef bswap_64
#define bswap_64(x) (((uint64_t)(x) << 56) | \
(((uint64_t)(x) << 40) & 0xff000000000000ULL) | \
(((uint64_t)(x) << 24) & 0xff0000000000ULL) | \
@@ -44,9 +41,11 @@
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define htonll(x) bswap_64(x)
#define ntohll(x) bswap_64(x)
-#else
+#elif __BYTE_ORDER == __BIG_ENDIAN
#define htonll(x) x
#define ntohll(x) x
+#else
+#error Unknown __BYTE_ORDER
#endif
enum TType {