$OpenBSD: patch-libhfsp_src_swab_h,v 1.5 2011/04/22 11:37:46 sthen Exp $
--- libhfsp/src/swab.h.orig	Tue Mar  5 19:50:29 2002
+++ libhfsp/src/swab.h	Sun Apr 17 09:50:06 2011
@@ -25,7 +25,12 @@
  */
 
+#if defined(__OpenBSD__)
+#include <sys/types.h>
+#include <sys/endian.h>
+#else
 #include <endian.h>
 #include <byteswap.h> 
+#endif
 
  /* basic fuction:
     value = swab_inc(ptr);
@@ -34,30 +39,58 @@
 
 #if BYTE_ORDER == LITTLE_ENDIAN
 
-#define bswabU16(val) bswap_16(val)
+#define bswabU16(val) swap16(val)
 
-#define bswabU16_inc(ptr) bswap_16(*((UInt16*) (ptr))++)
-#define bswabU32_inc(ptr) bswap_32(*((UInt32*) (ptr))++)
-#define bswabU64_inc(ptr) bswap_64(*((UInt64*) (ptr))++)
+#define bswabU16_inc(ptr)				\
+	swap16(*(UInt16 *)(ptr)), (ptr) = (((char *)(ptr)) + 2)
+#define bswabU32_inc(ptr)				\
+	swap32(*(UInt32 *)(ptr)), (ptr) = (((char *)(ptr)) + 4)
+#define bswabU64_inc(ptr)				\
+	swap64(*(UInt64 *)(ptr)), (ptr) = (((char *)(ptr)) + 8)
 
-#define bstoreU16_inc(ptr, val) (*((UInt16*) (ptr))++) = bswap_16(val)
-#define bstoreU32_inc(ptr, val) (*((UInt32*) (ptr))++) = bswap_32(val)
-#define bstoreU64_inc(ptr, val) (*((UInt64*) (ptr))++) = bswap_64(val)
+#define bstoreU16_inc(ptr, val)	do {			\
+	*(UInt16 *)(ptr) = swap16((val));		\
+	(ptr) = (((char *)(ptr)) + 2);			\
+} while(0)
+#define bstoreU32_inc(ptr, val)	do {			\
+	*(UInt32 *)(ptr) = swap32((val));		\
+	(ptr) = (((char *)(ptr)) + 4);			\
+} while(0)
+#define bstoreU64_inc(ptr, val)	do {			\
+	*(UInt64 *)(ptr) = swap64((val));		\
+	(ptr) = (((char *)(ptr)) + 8);			\
+} while(0)
 
 #else // BYTE_ORDER == BIG_ENDIAN
 
 #define bswabU16(val) val
 
-#define bswabU16_inc(ptr) (*((UInt16*) (ptr))++)
-#define bswabU32_inc(ptr) (*((UInt32*) (ptr))++)
-#define bswabU64_inc(ptr) (*((UInt64*) (ptr))++)
+#define bswabU16_inc(ptr)				\
+	*(UInt16 *)(ptr), (ptr) = (((char *)(ptr)) + 2)
+#define bswabU32_inc(ptr)				\
+	*(UInt32 *)(ptr), (ptr) = (((char *)(ptr)) + 4)
+#define bswabU64_inc(ptr)				\
+	*(UInt64 *)(ptr), (ptr) = (((char *)(ptr)) + 8)
 
-#define bstoreU16_inc(ptr, val) (*((UInt16*) (ptr))++) = val
-#define bstoreU32_inc(ptr, val) (*((UInt32*) (ptr))++) = val
-#define bstoreU64_inc(ptr, val) (*((UInt64*) (ptr))++) = val
+#define bstoreU16_inc(ptr, val)	do {			\
+	*(UInt16 *)(ptr) = (val);			\
+	(ptr) = (((char *)(ptr)) + 2);			\
+} while(0)
+#define bstoreU32_inc(ptr, val)	do {			\
+	*(UInt32 *)(ptr) = (val);			\
+	(ptr) = (((char *)(ptr)) + 4);			\
+} while(0)
+#define bstoreU64_inc(ptr, val)	do {			\
+	*(UInt64 *)(ptr) = (val);			\
+	(ptr) = (((char *)(ptr)) + 8);			\
+} while(0)
 
 #endif
 
-/* for the sake of compleetness and readability */
-#define bswabU8_inc(ptr)	(*((UInt8*) (ptr))++)
-#define bstoreU8_inc(ptr,val)	(*((UInt8*) (ptr))++) = val
+/* for the sake of completeness and readability */
+#define bswabU8_inc(ptr)				\
+	*(UInt8 *)(ptr), (ptr) = (((char *)(ptr)) + 1)
+#define bstoreU8_inc(ptr, val)	do {			\
+	*(UInt8 *)(ptr) = (val);			\
+	(ptr) = (((char *)(ptr)) + 1);			\
+} while(0)
