00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _tdsbytes_h_
00021 #define _tdsbytes_h_
00022
00023
00024
00025 #ifndef _tds_h_
00026 #error tds.h must be included before tdsbytes.h
00027 #endif
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #define TDS_GET_A1LE(ptr) (((TDS_UCHAR*)(ptr))[0])
00048 #define TDS_GET_A1BE(ptr) TDS_GET_A1LE(ptr)
00049 #define TDS_GET_UA1LE(ptr) TDS_GET_A1LE(ptr)
00050 #define TDS_GET_UA1BE(ptr) TDS_GET_A1LE(ptr)
00051
00052 #define TDS_PUT_A1LE(ptr,val) do { ((TDS_UCHAR*)(ptr))[0] = (val); } while(0)
00053 #define TDS_PUT_A1BE(ptr,val) TDS_PUT_A1LE(ptr,val)
00054 #define TDS_PUT_UA1LE(ptr,val) TDS_PUT_A1LE(ptr,val)
00055 #define TDS_PUT_UA1BE(ptr,val) TDS_PUT_A1LE(ptr,val)
00056
00057
00058 #define TDS_GET_UA2LE(ptr) (((TDS_UCHAR*)(ptr))[1] * 0x100u + ((TDS_UCHAR*)(ptr))[0])
00059 #define TDS_GET_UA2BE(ptr) (((TDS_UCHAR*)(ptr))[0] * 0x100u + ((TDS_UCHAR*)(ptr))[1])
00060 #define TDS_GET_A2LE(ptr) TDS_GET_UA2LE(ptr)
00061 #define TDS_GET_A2BE(ptr) TDS_GET_UA2BE(ptr)
00062
00063 #define TDS_PUT_UA2LE(ptr,val) do {\
00064 ((TDS_UCHAR*)(ptr))[1] = (val)>>8; ((TDS_UCHAR*)(ptr))[0] = (val); } while(0)
00065 #define TDS_PUT_UA2BE(ptr,val) do {\
00066 ((TDS_UCHAR*)(ptr))[0] = (val)>>8; ((TDS_UCHAR*)(ptr))[1] = (val); } while(0)
00067 #define TDS_PUT_A2LE(ptr,val) TDS_PUT_UA2LE(ptr,val)
00068 #define TDS_PUT_A2BE(ptr,val) TDS_PUT_UA2BE(ptr,val)
00069
00070
00071 #define TDS_GET_UA4LE(ptr) \
00072 (((TDS_UCHAR*)(ptr))[3] * 0x1000000u + ((TDS_UCHAR*)(ptr))[2] * 0x10000u +\
00073 ((TDS_UCHAR*)(ptr))[1] * 0x100u + ((TDS_UCHAR*)(ptr))[0])
00074 #define TDS_GET_UA4BE(ptr) \
00075 (((TDS_UCHAR*)(ptr))[0] * 0x1000000u + ((TDS_UCHAR*)(ptr))[1] * 0x10000u +\
00076 ((TDS_UCHAR*)(ptr))[2] * 0x100u + ((TDS_UCHAR*)(ptr))[3])
00077 #define TDS_GET_A4LE(ptr) TDS_GET_UA4LE(ptr)
00078 #define TDS_GET_A4BE(ptr) TDS_GET_UA4BE(ptr)
00079
00080 #define TDS_PUT_UA4LE(ptr,val) do {\
00081 ((TDS_UCHAR*)(ptr))[3] = (val)>>24; ((TDS_UCHAR*)(ptr))[2] = (val)>>16;\
00082 ((TDS_UCHAR*)(ptr))[1] = (val)>>8; ((TDS_UCHAR*)(ptr))[0] = (val); } while(0)
00083 #define TDS_PUT_UA4BE(ptr,val) do {\
00084 ((TDS_UCHAR*)(ptr))[0] = (val)>>24; ((TDS_UCHAR*)(ptr))[1] = (val)>>16;\
00085 ((TDS_UCHAR*)(ptr))[2] = (val)>>8; ((TDS_UCHAR*)(ptr))[3] = (val); } while(0)
00086 #define TDS_PUT_A4LE(ptr,val) TDS_PUT_UA4LE(ptr,val)
00087 #define TDS_PUT_A4BE(ptr,val) TDS_PUT_UA4BE(ptr,val)
00088
00089
00090 #ifdef WORDS_BIGENDIAN
00091 # define TDS_GET_A1(ptr) TDS_GET_A1BE(ptr)
00092 # define TDS_GET_UA1(ptr) TDS_GET_UA1BE(ptr)
00093 # define TDS_GET_A2(ptr) TDS_GET_A2BE(ptr)
00094 # define TDS_GET_UA2(ptr) TDS_GET_UA2BE(ptr)
00095 # define TDS_GET_A4(ptr) TDS_GET_A4BE(ptr)
00096 # define TDS_GET_UA4(ptr) TDS_GET_UA4BE(ptr)
00097 # undef TDS_GET_A2BE
00098 # undef TDS_GET_A4BE
00099 # define TDS_GET_A2BE(ptr) (*((TDS_USMALLINT*)(ptr)))
00100 # define TDS_GET_A4BE(ptr) (*((TDS_UINT*)(ptr)))
00101
00102 # define TDS_PUT_A1(ptr,val) TDS_PUT_A1BE(ptr,val)
00103 # define TDS_PUT_UA1(ptr,val) TDS_PUT_UA1BE(ptr,val)
00104 # define TDS_PUT_A2(ptr,val) TDS_PUT_A2BE(ptr,val)
00105 # define TDS_PUT_UA2(ptr,val) TDS_PUT_UA2BE(ptr,val)
00106 # define TDS_PUT_A4(ptr,val) TDS_PUT_A4BE(ptr,val)
00107 # define TDS_PUT_UA4(ptr,val) TDS_PUT_UA4BE(ptr,val)
00108 # undef TDS_PUT_A2BE
00109 # undef TDS_PUT_A4BE
00110 # define TDS_PUT_A2BE(ptr,val) (*((TDS_USMALLINT*)(ptr)) = (val))
00111 # define TDS_PUT_A4BE(ptr,val) (*((TDS_UINT*)(ptr)) = (val))
00112 #else
00113 # define TDS_GET_A1(ptr) TDS_GET_A1LE(ptr)
00114 # define TDS_GET_UA1(ptr) TDS_GET_UA1LE(ptr)
00115 # define TDS_GET_A2(ptr) TDS_GET_A2LE(ptr)
00116 # define TDS_GET_UA2(ptr) TDS_GET_UA2LE(ptr)
00117 # define TDS_GET_A4(ptr) TDS_GET_A4LE(ptr)
00118 # define TDS_GET_UA4(ptr) TDS_GET_UA4LE(ptr)
00119 # undef TDS_GET_A2LE
00120 # undef TDS_GET_A4LE
00121 # define TDS_GET_A2LE(ptr) (*((TDS_USMALLINT*)(ptr)))
00122 # define TDS_GET_A4LE(ptr) (*((TDS_UINT*)(ptr)))
00123
00124 # define TDS_PUT_A1(ptr,val) TDS_PUT_A1LE(ptr,val)
00125 # define TDS_PUT_UA1(ptr,val) TDS_PUT_UA1LE(ptr,val)
00126 # define TDS_PUT_A2(ptr,val) TDS_PUT_A2LE(ptr,val)
00127 # define TDS_PUT_UA2(ptr,val) TDS_PUT_UA2LE(ptr,val)
00128 # define TDS_PUT_A4(ptr,val) TDS_PUT_A4LE(ptr,val)
00129 # define TDS_PUT_UA4(ptr,val) TDS_PUT_UA4LE(ptr,val)
00130 # undef TDS_PUT_A2LE
00131 # undef TDS_PUT_A4LE
00132 # define TDS_PUT_A2LE(ptr,val) (*((TDS_USMALLINT*)(ptr)) = (val))
00133 # define TDS_PUT_A4LE(ptr,val) (*((TDS_UINT*)(ptr)) = (val))
00134 #endif
00135
00136
00137 #if defined(__i386__) || defined(__amd64__) || defined(__CRIS__) ||\
00138 defined(__powerpc__) || defined(__powerpc64__) || defined(__ppc__) || defined(__ppc64__) ||\
00139 defined(__s390__) || defined(__s390x__) || defined(__m68k__)
00140 # ifdef WORDS_BIGENDIAN
00141 # undef TDS_GET_UA2BE
00142 # undef TDS_GET_UA4BE
00143 # define TDS_GET_UA2BE(ptr) TDS_GET_A2BE(ptr)
00144 # define TDS_GET_UA4BE(ptr) TDS_GET_A4BE(ptr)
00145
00146 # undef TDS_PUT_UA2BE
00147 # undef TDS_PUT_UA4BE
00148 # define TDS_PUT_UA2BE(ptr,val) TDS_PUT_A2BE(ptr,val)
00149 # define TDS_PUT_UA4BE(ptr,val) TDS_PUT_A4BE(ptr,val)
00150 # else
00151 # undef TDS_GET_UA2LE
00152 # undef TDS_GET_UA4LE
00153 # define TDS_GET_UA2LE(ptr) TDS_GET_A2LE(ptr)
00154 # define TDS_GET_UA4LE(ptr) TDS_GET_A4LE(ptr)
00155
00156 # undef TDS_PUT_UA2LE
00157 # undef TDS_PUT_UA4LE
00158 # define TDS_PUT_UA2LE(ptr,val) TDS_PUT_A2LE(ptr,val)
00159 # define TDS_PUT_UA4LE(ptr,val) TDS_PUT_A4LE(ptr,val)
00160 # endif
00161 #endif
00162
00163 #if defined(__linux__) && defined(__GNUC__) && defined(__i386__)
00164 # include <byteswap.h>
00165 # undef TDS_GET_UA2BE
00166 # undef TDS_GET_UA4BE
00167 # define TDS_GET_UA2BE(ptr) ({ TDS_USMALLINT _tds_si = TDS_GET_UA2LE(ptr); bswap_16(_tds_si); })
00168 # define TDS_GET_UA4BE(ptr) ({ TDS_UINT _tds_i = TDS_GET_UA4LE(ptr); bswap_32(_tds_i); })
00169
00170 # undef TDS_PUT_UA2BE
00171 # undef TDS_PUT_UA4BE
00172 # define TDS_PUT_UA2BE(ptr,val) do {\
00173 TDS_USMALLINT _tds_si = bswap_16(val); TDS_PUT_UA2LE(ptr,_tds_si); } while(0)
00174 # define TDS_PUT_UA4BE(ptr,val) do {\
00175 TDS_UINT _tds_i = bswap_32(val); TDS_PUT_UA4LE(ptr,_tds_i); } while(0)
00176 #endif
00177
00178 #endif