00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef _DB_SWAP_H_
00039 #define _DB_SWAP_H_
00040
00041
00042
00043
00044
00045
00046
00047 #undef M_64_SWAP
00048 #define M_64_SWAP(a) { \
00049 u_int64_t _tmp; \
00050 _tmp = (u_int64_t)a; \
00051 ((u_int8_t *)&a)[0] = ((u_int8_t *)&_tmp)[7]; \
00052 ((u_int8_t *)&a)[1] = ((u_int8_t *)&_tmp)[6]; \
00053 ((u_int8_t *)&a)[2] = ((u_int8_t *)&_tmp)[5]; \
00054 ((u_int8_t *)&a)[3] = ((u_int8_t *)&_tmp)[4]; \
00055 ((u_int8_t *)&a)[4] = ((u_int8_t *)&_tmp)[3]; \
00056 ((u_int8_t *)&a)[5] = ((u_int8_t *)&_tmp)[2]; \
00057 ((u_int8_t *)&a)[6] = ((u_int8_t *)&_tmp)[1]; \
00058 ((u_int8_t *)&a)[7] = ((u_int8_t *)&_tmp)[0]; \
00059 }
00060 #undef P_64_COPY
00061 #define P_64_COPY(a, b) { \
00062 ((u_int8_t *)b)[0] = ((u_int8_t *)a)[0]; \
00063 ((u_int8_t *)b)[1] = ((u_int8_t *)a)[1]; \
00064 ((u_int8_t *)b)[2] = ((u_int8_t *)a)[2]; \
00065 ((u_int8_t *)b)[3] = ((u_int8_t *)a)[3]; \
00066 ((u_int8_t *)b)[4] = ((u_int8_t *)a)[4]; \
00067 ((u_int8_t *)b)[5] = ((u_int8_t *)a)[5]; \
00068 ((u_int8_t *)b)[6] = ((u_int8_t *)a)[6]; \
00069 ((u_int8_t *)b)[7] = ((u_int8_t *)a)[7]; \
00070 }
00071 #undef P_64_SWAP
00072 #define P_64_SWAP(a) { \
00073 u_int64_t _tmp; \
00074 P_64_COPY(a, &_tmp); \
00075 ((u_int8_t *)a)[0] = ((u_int8_t *)&_tmp)[7]; \
00076 ((u_int8_t *)a)[1] = ((u_int8_t *)&_tmp)[6]; \
00077 ((u_int8_t *)a)[2] = ((u_int8_t *)&_tmp)[5]; \
00078 ((u_int8_t *)a)[3] = ((u_int8_t *)&_tmp)[4]; \
00079 ((u_int8_t *)a)[4] = ((u_int8_t *)&_tmp)[3]; \
00080 ((u_int8_t *)a)[5] = ((u_int8_t *)&_tmp)[2]; \
00081 ((u_int8_t *)a)[6] = ((u_int8_t *)&_tmp)[1]; \
00082 ((u_int8_t *)a)[7] = ((u_int8_t *)&_tmp)[0]; \
00083 }
00084
00085
00086
00087
00088
00089
00090
00091 #undef M_32_SWAP
00092 #define M_32_SWAP(a) { \
00093 u_int32_t _tmp; \
00094 _tmp = (u_int32_t)a; \
00095 ((u_int8_t *)&a)[0] = ((u_int8_t *)&_tmp)[3]; \
00096 ((u_int8_t *)&a)[1] = ((u_int8_t *)&_tmp)[2]; \
00097 ((u_int8_t *)&a)[2] = ((u_int8_t *)&_tmp)[1]; \
00098 ((u_int8_t *)&a)[3] = ((u_int8_t *)&_tmp)[0]; \
00099 }
00100 #undef P_32_COPY
00101 #define P_32_COPY(a, b) { \
00102 ((u_int8_t *)b)[0] = ((u_int8_t *)a)[0]; \
00103 ((u_int8_t *)b)[1] = ((u_int8_t *)a)[1]; \
00104 ((u_int8_t *)b)[2] = ((u_int8_t *)a)[2]; \
00105 ((u_int8_t *)b)[3] = ((u_int8_t *)a)[3]; \
00106 }
00107 #undef P_32_SWAP
00108 #define P_32_SWAP(a) { \
00109 u_int32_t _tmp; \
00110 P_32_COPY(a, &_tmp); \
00111 ((u_int8_t *)a)[0] = ((u_int8_t *)&_tmp)[3]; \
00112 ((u_int8_t *)a)[1] = ((u_int8_t *)&_tmp)[2]; \
00113 ((u_int8_t *)a)[2] = ((u_int8_t *)&_tmp)[1]; \
00114 ((u_int8_t *)a)[3] = ((u_int8_t *)&_tmp)[0]; \
00115 }
00116
00117
00118
00119
00120
00121
00122
00123 #undef M_16_SWAP
00124 #define M_16_SWAP(a) { \
00125 u_int16_t _tmp; \
00126 _tmp = (u_int16_t)a; \
00127 ((u_int8_t *)&a)[0] = ((u_int8_t *)&_tmp)[1]; \
00128 ((u_int8_t *)&a)[1] = ((u_int8_t *)&_tmp)[0]; \
00129 }
00130 #undef P_16_COPY
00131 #define P_16_COPY(a, b) { \
00132 ((u_int8_t *)b)[0] = ((u_int8_t *)a)[0]; \
00133 ((u_int8_t *)b)[1] = ((u_int8_t *)a)[1]; \
00134 }
00135 #undef P_16_SWAP
00136 #define P_16_SWAP(a) { \
00137 u_int16_t _tmp; \
00138 P_16_COPY(a, &_tmp); \
00139 ((u_int8_t *)a)[0] = ((u_int8_t *)&_tmp)[1]; \
00140 ((u_int8_t *)a)[1] = ((u_int8_t *)&_tmp)[0]; \
00141 }
00142
00143 #undef SWAP32
00144 #define SWAP32(p) { \
00145 P_32_SWAP(p); \
00146 (p) += sizeof(u_int32_t); \
00147 }
00148 #undef SWAP16
00149 #define SWAP16(p) { \
00150 P_16_SWAP(p); \
00151 (p) += sizeof(u_int16_t); \
00152 }
00153
00154
00155
00156
00157
00158
00159 #undef DB_HTONL
00160 #define DB_HTONL(p) do { \
00161 if (!__db_isbigendian()) \
00162 P_32_SWAP(p); \
00163 } while (0)
00164 #undef DB_NTOHL
00165 #define DB_NTOHL(p) do { \
00166 if (!__db_isbigendian()) \
00167 P_32_SWAP(p); \
00168 } while (0)
00169
00170 #endif