OSDN Git Service

Added byte order macros for FreeBSD, DragonFlyBSD, NetBSD, OpenBSD and Solaris.
authorresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Sat, 26 Jun 2010 15:04:07 +0000 (15:04 +0000)
committerresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Sat, 26 Jun 2010 15:04:07 +0000 (15:04 +0000)
Signed-off-by: Albert Lee <triskelios@gmail.com>
git-svn-id: http://exfat.googlecode.com/svn/trunk@146 60bc1c72-a15a-11de-b98f-4500b42dc123

libexfat/byteorder.h

index 1e25f2c..6b38646 100644 (file)
 
 #include <stdint.h>
 
-#ifdef __APPLE__
+#if defined(__GLIBC__)
+
+#include <endian.h>
+#include <byteswap.h>
+
+#elif defined(__APPLE__)
+
 #include <machine/endian.h>
 #include <libkern/OSByteOrder.h>
 #define bswap_16(x) OSSwapInt16(x)
 #define bswap_32(x) OSSwapInt32(x)
 #define bswap_64(x) OSSwapInt64(x)
-/* GNU endian macros have "__" prefix, BSD ones don't */
 #define __BYTE_ORDER BYTE_ORDER
 #define __LITTLE_ENDIAN LITTLE_ENDIAN
 #define __BIG_ENDIAN BIG_ENDIAN
+
+#elif defined(__FreeBSD__) || defined(__DragonFlyBSD__) || defined(__NetBSD__)
+
+#include <sys/endian.h>
+#define bswap_16(x) bswap16(x)
+#define bswap_32(x) bswap32(x)
+#define bswap_64(x) bswap64(x)
+#define __BYTE_ORDER _BYTE_ORDER
+#define __LITTLE_ENDIAN _LITTLE_ENDIAN
+#define __BIG_ENDIAN _BIG_ENDIAN
+
+#elif defined(__OpenBSD__)
+
+#include <machine/endian.h>
+#define bswap_16(x) swap16(x)
+#define bswap_32(x) swap32(x)
+#define bswap_64(x) swap64(x)
+#define __BYTE_ORDER _BYTE_ORDER
+#define __LITTLE_ENDIAN _LITTLE_ENDIAN
+#define __BIG_ENDIAN _BIG_ENDIAN
+
+#elif defined(__sun)
+
+#include <sys/byteorder.h>
+#define bswap_16(x) BSWAP_16(x)
+#define bswap_32(x) BSWAP_32(x)
+#define bswap_64(x) BSWAP_64(x)
+#define __LITTLE_ENDIAN 1234
+#define __BIG_ENDIAN 4321
+#ifdef _LITTLE_ENDIAN
+#define __BYTE_ORDER __LITTLE_ENDIAN
 #else
-#include <endian.h>
-#include <byteswap.h>
+#define __BYTE_ORDER __BIG_ENDIAN
+#endif
+
+#else 
+#error No byte order macros available for your platform
 #endif
 
 typedef struct { uint16_t __u16; } le16_t;