THRIFT-682. php: PHP extension doesn't compile on Mac OS X
authorBryan Duxbury <bryanduxbury@apache.org>
Fri, 13 Aug 2010 00:17:16 +0000 (00:17 +0000)
committerBryan Duxbury <bryanduxbury@apache.org>
Fri, 13 Aug 2010 00:17:16 +0000 (00:17 +0000)
This patch adds a bswap_64 implementation for OS X users.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@985050 13f79535-47bb-0310-9956-ffa450edef68

lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp

index 641fff2..193669b 100644 (file)
 #include <sys/types.h>
 #include <netinet/in.h>
 #include <unistd.h>
-#include <endian.h>
-#include <byteswap.h>
+#include <machine/endian.h>
+#include <machine/byte_order.h>
 #include <stdexcept>
 
+#ifndef _BYTESWAP_H
+#define _BYTESWAP_H
+
+#define        bswap_64(x)     (((uint64_t)(x) << 56) | \
+                        (((uint64_t)(x) << 40) & 0xff000000000000ULL) | \
+                        (((uint64_t)(x) << 24) & 0xff0000000000ULL) | \
+                        (((uint64_t)(x) << 8)  & 0xff00000000ULL) | \
+                        (((uint64_t)(x) >> 8)  & 0xff000000ULL) | \
+                        (((uint64_t)(x) >> 24) & 0xff0000ULL) | \
+                        (((uint64_t)(x) >> 40) & 0xff00ULL) | \
+                        ((uint64_t)(x)  >> 56))
+#endif
+
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 #define htonll(x) bswap_64(x)
 #define ntohll(x) bswap_64(x)