00001 #include <sys/types.h>
00002 #include <sys/param.h>
00003
00004 #ifndef htole32
00005 #if BYTE_ORDER == LITTLE_ENDIAN
00006 #define htole32(x) (x)
00007 #else
00008 #if BYTE_ORDER == BIG_ENDIAN
00009 #define htole32(x) \
00010 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
00011 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
00012 #else
00013 #error No endianness given.
00014 #endif
00015 #endif
00016 #endif
00017
00018 #ifndef htole64
00019 #if BYTE_ORDER == LITTLE_ENDIAN
00020 #define htole64(x) (x)
00021 #else
00022 #if BYTE_ORDER == BIG_ENDIAN
00023 #define htole64(x) \
00024 ( (((x) & 0xff00000000000000ull) >> 56) \
00025 | (((x) & 0x00ff000000000000ull) >> 40) \
00026 | (((x) & 0x0000ff0000000000ull) >> 24) \
00027 | (((x) & 0x000000ff00000000ull) >> 8) \
00028 | (((x) & 0x00000000ff000000ull) << 8) \
00029 | (((x) & 0x0000000000ff0000ull) << 24) \
00030 | (((x) & 0x000000000000ff00ull) << 40) \
00031 | (((x) & 0x00000000000000ffull) << 56))
00032 #else
00033 #error No endianness given.
00034 #endif
00035 #endif
00036 #endif