00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __BARRY_ENDIAN_H__
00023 #define __BARRY_ENDIAN_H__
00024
00025
00026
00027 #include "config.h"
00028
00029 #ifndef WORDS_BIGENDIAN
00030 #define btohs(x) x // for uint16_t
00031 #define btohl(x) x // for uint32_t
00032 #define btohll(x) x // for uint64_t
00033 #define htobs(x) x // for uint16_t
00034 #define htobl(x) x // for uint32_t
00035 #define htobll(x) x // for uint64_t
00036 #else
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 static inline unsigned short bswap_16(unsigned short x) {
00048 return (x>>8) | (x<<8);
00049 }
00050
00051 static inline unsigned int bswap_32(unsigned int x) {
00052 return (bswap_16(x&0xffff)<<16) | (bswap_16(x>>16));
00053 }
00054
00055 static inline unsigned long long bswap_64(unsigned long long x) {
00056 return (((unsigned long long)bswap_32(x&0xffffffffull))<<32) | (bswap_32(x>>32));
00057 }
00058
00059 #define btohs(x) bswap_16(x) // for uint16_t
00060 #define btohl(x) bswap_32(x) // for uint32_t
00061 #define btohll(x) bswap_64(x) // for uint64_t
00062 #define htobs(x) bswap_16(x) // for uint16_t
00063 #define htobl(x) bswap_32(x) // for uint32_t
00064 #define htobll(x) bswap_64(x) // for uint64_t
00065 #endif
00066
00067 #endif
00068