00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _RA_ENDIAN_H
00019 #define _RA_ENDIAN_H
00020
00021 #ifdef __cplusplus
00022 extern "C" {
00023 #endif
00024
00025 #define RA_LITTLE_ENDIAN 1
00026 #define RA_BIG_ENDIAN 2
00027
00028 #define _swap16(x,l) \
00029 do { \
00030 short endian_t = x; \
00031 int endian_type = get_endian_type(); \
00032 \
00033 if (l && (endian_type == RA_LITTLE_ENDIAN)) \
00034 break; \
00035 if (!l && (endian_type == RA_BIG_ENDIAN)) \
00036 break; \
00037 \
00038 x = ((endian_t & 0x00ff) << 8) | \
00039 ((endian_t & 0xff00) >> 8); \
00040 } while(0)
00041
00042 #define _swap32(x,l) \
00043 do { \
00044 long endian_t = x; \
00045 int endian_type = get_endian_type(); \
00046 \
00047 if (l && (endian_type == RA_LITTLE_ENDIAN)) \
00048 break; \
00049 if (!l && (endian_type == RA_BIG_ENDIAN)) \
00050 break; \
00051 \
00052 x = ((endian_t & 0x000000ff) << 24) | \
00053 ((endian_t & 0x0000ff00) << 8) | \
00054 ((endian_t & 0x00ff0000) >> 8) | \
00055 ((endian_t & 0xff000000) >> 24); \
00056 } while(0)
00057
00058
00059 #define be16_to_cpu(x) _swap16(x,0)
00060 #define be32_to_cpu(x) _swap32(x,0)
00061
00062 #define le16_to_cpu(x) _swap16(x,1)
00063 #define le32_to_cpu(x) _swap32(x,1)
00064
00065
00066 #ifdef __cplusplus
00067 }
00068 #endif
00069
00070 #endif