[Box Backup-dev] COMMIT r257 - in box/trunk: . lib/common

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Wed, 21 Dec 2005 00:23:12 +0000 (GMT)


Author: martin
Date: 2005-12-21 00:23:10 +0000 (Wed, 21 Dec 2005)
New Revision: 257

Modified:
   box/trunk/configure.ac
   box/trunk/lib/common/Box.h
Log:
Allow use of native 64 bit endian swapping functions

Modified: box/trunk/configure.ac
===================================================================
--- box/trunk/configure.ac	2005-12-20 23:34:09 UTC (rev 256)
+++ box/trunk/configure.ac	2005-12-21 00:23:10 UTC (rev 257)
@@ -65,6 +65,7 @@
 AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
 AC_CHECK_HEADERS([execinfo.h netinet/in.h regex.h sys/types.h sys/xattr.h])
+AC_CHECK_HEADERS([sys/endian.h asm/byteorder.h])
 
 
 ### Checks for typedefs, structures, and compiler characteristics.

Modified: box/trunk/lib/common/Box.h
===================================================================
--- box/trunk/lib/common/Box.h	2005-12-20 23:34:09 UTC (rev 256)
+++ box/trunk/lib/common/Box.h	2005-12-21 00:23:10 UTC (rev 257)
@@ -114,6 +114,10 @@
 
 // extra macros for converting to network byte order
 
+#ifdef HAVE_NETINET_IN_H
+	#include <netinet/in.h>
+#endif
+
 // Always define a swap64 function, as it's useful.
 inline uint64_t box_swap64(uint64_t x)
 {
@@ -131,13 +135,19 @@
 	#define box_hton64(x) (x)
 	#define box_ntoh64(x) (x)
 #else
-	#define box_hton64(x) box_swap64(x)
-	#define box_ntoh64(x) box_swap64(x)
+	#ifdef HAVE_SYS_ENDIAN_H
+		#include <sys/endian.h>
+		#define box_hton64(x) htobe64(x)
+		#define box_ntoh64(x) betoh64(x)
+	#elif HAVE_ASM_BYTEORDER_H
+		#include <asm/byteorder.h>
+		#define box_hton64(x) __cpu_to_be64(x)
+		#define box_ntoh64(x) __be64_to_cpu(x)
+	#else
+		#define box_hton64(x) box_swap64(x)
+		#define box_ntoh64(x) box_swap64(x)
+	#endif
 #endif
 
-#ifdef HAVE_NETINET_IN_H
-	#include <netinet/in.h>
-#endif
-
 #endif // BOX__H