Go to the documentation of this file.Go to the SVN repository for this file.
24 #error tds.h must be included before bytes.h
45 #define TDS_GET_A1LE(ptr) (((TDS_UCHAR*)(ptr))[0])
46 #define TDS_GET_A1BE(ptr) TDS_GET_A1LE(ptr)
47 #define TDS_GET_UA1LE(ptr) TDS_GET_A1LE(ptr)
48 #define TDS_GET_UA1BE(ptr) TDS_GET_A1LE(ptr)
50 #define TDS_PUT_A1LE(ptr,val) do { ((TDS_UCHAR*)(ptr))[0] = (val); } while(0)
51 #define TDS_PUT_A1BE(ptr,val) TDS_PUT_A1LE(ptr,val)
52 #define TDS_PUT_UA1LE(ptr,val) TDS_PUT_A1LE(ptr,val)
53 #define TDS_PUT_UA1BE(ptr,val) TDS_PUT_A1LE(ptr,val)
56 #define TDS_GET_UA2LE(ptr) (((TDS_UCHAR*)(ptr))[1] * 0x100u + ((TDS_UCHAR*)(ptr))[0])
57 #define TDS_GET_UA2BE(ptr) (((TDS_UCHAR*)(ptr))[0] * 0x100u + ((TDS_UCHAR*)(ptr))[1])
58 #define TDS_GET_A2LE(ptr) TDS_GET_UA2LE(ptr)
59 #define TDS_GET_A2BE(ptr) TDS_GET_UA2BE(ptr)
61 #define TDS_PUT_UA2LE(ptr,val) do {\
62 ((TDS_UCHAR*)(ptr))[1] = (TDS_UCHAR)((val)>>8); ((TDS_UCHAR*)(ptr))[0] = (TDS_UCHAR)(val); } while(0)
63 #define TDS_PUT_UA2BE(ptr,val) do {\
64 ((TDS_UCHAR*)(ptr))[0] = (TDS_UCHAR)((val)>>8); ((TDS_UCHAR*)(ptr))[1] = (TDS_UCHAR)(val); } while(0)
65 #define TDS_PUT_A2LE(ptr,val) TDS_PUT_UA2LE(ptr,val)
66 #define TDS_PUT_A2BE(ptr,val) TDS_PUT_UA2BE(ptr,val)
69 #define TDS_GET_UA4LE(ptr) \
70 (((TDS_UCHAR*)(ptr))[3] * 0x1000000u + ((TDS_UCHAR*)(ptr))[2] * 0x10000u +\
71 ((TDS_UCHAR*)(ptr))[1] * 0x100u + ((TDS_UCHAR*)(ptr))[0])
72 #define TDS_GET_UA4BE(ptr) \
73 (((TDS_UCHAR*)(ptr))[0] * 0x1000000u + ((TDS_UCHAR*)(ptr))[1] * 0x10000u +\
74 ((TDS_UCHAR*)(ptr))[2] * 0x100u + ((TDS_UCHAR*)(ptr))[3])
75 #define TDS_GET_A4LE(ptr) TDS_GET_UA4LE(ptr)
76 #define TDS_GET_A4BE(ptr) TDS_GET_UA4BE(ptr)
78 #define TDS_PUT_UA4LE(ptr,val) do {\
79 ((TDS_UCHAR*)(ptr))[3] = (TDS_UCHAR)((val)>>24); ((TDS_UCHAR*)(ptr))[2] = (TDS_UCHAR)((val)>>16);\
80 ((TDS_UCHAR*)(ptr))[1] = (TDS_UCHAR)((val)>>8); ((TDS_UCHAR*)(ptr))[0] = (TDS_UCHAR)(val); } while(0)
81 #define TDS_PUT_UA4BE(ptr,val) do {\
82 ((TDS_UCHAR*)(ptr))[0] = (TDS_UCHAR)((val)>>24); ((TDS_UCHAR*)(ptr))[1] = (TDS_UCHAR)((val)>>16);\
83 ((TDS_UCHAR*)(ptr))[2] = (TDS_UCHAR)((val)>>8); ((TDS_UCHAR*)(ptr))[3] = (TDS_UCHAR)(val); } while(0)
84 #define TDS_PUT_A4LE(ptr,val) TDS_PUT_UA4LE(ptr,val)
85 #define TDS_PUT_A4BE(ptr,val) TDS_PUT_UA4BE(ptr,val)
88 # define TDS_MAY_ALIAS __attribute__((__may_alias__))
90 # define TDS_MAY_ALIAS
105 #ifdef WORDS_BIGENDIAN
106 # define TDS_GET_A1(ptr) TDS_GET_A1BE(ptr)
107 # define TDS_GET_UA1(ptr) TDS_GET_UA1BE(ptr)
108 # define TDS_GET_A2(ptr) TDS_GET_A2BE(ptr)
109 # define TDS_GET_UA2(ptr) TDS_GET_UA2BE(ptr)
110 # define TDS_GET_A4(ptr) TDS_GET_A4BE(ptr)
111 # define TDS_GET_UA4(ptr) TDS_GET_UA4BE(ptr)
114 # define TDS_GET_A2BE(ptr) (((TDS_BYTE_CONVERT2*)(ptr))->usi)
115 # define TDS_GET_A4BE(ptr) (((TDS_BYTE_CONVERT4*)(ptr))->ui)
117 # define TDS_PUT_A1(ptr,val) TDS_PUT_A1BE(ptr,val)
118 # define TDS_PUT_UA1(ptr,val) TDS_PUT_UA1BE(ptr,val)
119 # define TDS_PUT_A2(ptr,val) TDS_PUT_A2BE(ptr,val)
120 # define TDS_PUT_UA2(ptr,val) TDS_PUT_UA2BE(ptr,val)
121 # define TDS_PUT_A4(ptr,val) TDS_PUT_A4BE(ptr,val)
122 # define TDS_PUT_UA4(ptr,val) TDS_PUT_UA4BE(ptr,val)
125 # define TDS_PUT_A2BE(ptr,val) (((TDS_BYTE_CONVERT2*)(ptr))->usi = (val))
126 # define TDS_PUT_A4BE(ptr,val) (((TDS_BYTE_CONVERT4*)(ptr))->ui = (val))
127 # define TDS_HOST2LE(val) TDS_BYTE_SWAP16(val)
128 # define TDS_HOST4LE(val) TDS_BYTE_SWAP32(val)
129 # define TDS_HOST2BE(val) (val)
130 # define TDS_HOST4BE(val) (val)
132 # define TDS_GET_A1(ptr) TDS_GET_A1LE(ptr)
133 # define TDS_GET_UA1(ptr) TDS_GET_UA1LE(ptr)
134 # define TDS_GET_A2(ptr) TDS_GET_A2LE(ptr)
135 # define TDS_GET_UA2(ptr) TDS_GET_UA2LE(ptr)
136 # define TDS_GET_A4(ptr) TDS_GET_A4LE(ptr)
137 # define TDS_GET_UA4(ptr) TDS_GET_UA4LE(ptr)
140 # define TDS_GET_A2LE(ptr) (((TDS_BYTE_CONVERT2*)(ptr))->usi)
141 # define TDS_GET_A4LE(ptr) (((TDS_BYTE_CONVERT4*)(ptr))->ui)
143 # define TDS_PUT_A1(ptr,val) TDS_PUT_A1LE(ptr,val)
144 # define TDS_PUT_UA1(ptr,val) TDS_PUT_UA1LE(ptr,val)
145 # define TDS_PUT_A2(ptr,val) TDS_PUT_A2LE(ptr,val)
146 # define TDS_PUT_UA2(ptr,val) TDS_PUT_UA2LE(ptr,val)
147 # define TDS_PUT_A4(ptr,val) TDS_PUT_A4LE(ptr,val)
148 # define TDS_PUT_UA4(ptr,val) TDS_PUT_UA4LE(ptr,val)
151 # define TDS_PUT_A2LE(ptr,val) (((TDS_BYTE_CONVERT2*)(ptr))->usi = (val))
152 # define TDS_PUT_A4LE(ptr,val) (((TDS_BYTE_CONVERT4*)(ptr))->ui = (val))
153 # define TDS_HOST2LE(val) (val)
154 # define TDS_HOST4LE(val) (val)
155 # define TDS_HOST2BE(val) TDS_BYTE_SWAP16(val)
156 # define TDS_HOST4BE(val) TDS_BYTE_SWAP32(val)
161 #if defined(__i386__) || defined(__amd64__) || defined(__CRIS__) ||\
162 defined(__powerpc__) || defined(__powerpc64__) || defined(__ppc__) || defined(__ppc64__) ||\
163 defined(__s390__) || defined(__s390x__) || defined(__m68k__) ||\
164 (defined(_MSC_VER) && (defined(_M_AMD64) || defined(_M_IX86) || defined(_M_X64))) ||\
165 defined(__ARM_FEATURE_UNALIGNED) ||\
166 defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_8__) ||\
167 (defined(_M_ARM) && (_M_ARM >= 7))
168 # ifdef WORDS_BIGENDIAN
169 # undef TDS_GET_UA2BE
170 # undef TDS_GET_UA4BE
171 # define TDS_GET_UA2BE(ptr) TDS_GET_A2BE(ptr)
172 # define TDS_GET_UA4BE(ptr) TDS_GET_A4BE(ptr)
174 # undef TDS_PUT_UA2BE
175 # undef TDS_PUT_UA4BE
176 # define TDS_PUT_UA2BE(ptr,val) TDS_PUT_A2BE(ptr,val)
177 # define TDS_PUT_UA4BE(ptr,val) TDS_PUT_A4BE(ptr,val)
179 # undef TDS_GET_UA2LE
180 # undef TDS_GET_UA4LE
181 # define TDS_GET_UA2LE(ptr) TDS_GET_A2LE(ptr)
182 # define TDS_GET_UA4LE(ptr) TDS_GET_A4LE(ptr)
184 # undef TDS_PUT_UA2LE
185 # undef TDS_PUT_UA4LE
186 # define TDS_PUT_UA2LE(ptr,val) TDS_PUT_A2LE(ptr,val)
187 # define TDS_PUT_UA4LE(ptr,val) TDS_PUT_A4LE(ptr,val)
191 #if defined(__linux__) && defined(__GNUC__) && (defined(__i386__) || defined(__amd64__))
192 # include <byteswap.h>
193 # undef TDS_GET_UA2BE
194 # undef TDS_GET_UA4BE
195 # define TDS_GET_UA2BE(ptr) ({ TDS_USMALLINT _tds_si = TDS_GET_UA2LE(ptr); bswap_16(_tds_si); })
196 # define TDS_GET_UA4BE(ptr) ({ TDS_UINT _tds_i = TDS_GET_UA4LE(ptr); bswap_32(_tds_i); })
198 # undef TDS_PUT_UA2BE
199 # undef TDS_PUT_UA4BE
200 # define TDS_PUT_UA2BE(ptr,val) do {\
201 TDS_USMALLINT _tds_si = bswap_16(val); TDS_PUT_UA2LE(ptr,_tds_si); } while(0)
202 # define TDS_PUT_UA4BE(ptr,val) do {\
203 TDS_UINT _tds_i = bswap_32(val); TDS_PUT_UA4LE(ptr,_tds_i); } while(0)
206 #if defined(__GNUC__) && defined(__powerpc__)
207 # undef TDS_GET_UA2LE
208 # undef TDS_GET_UA4LE
213 __asm__ (
"lhbrx %0,0,%1\n" :
"=r" (res) :
"r" (ptr),
"m"(*(
TDS_USMALLINT*)ptr));
220 __asm__ (
"lwbrx %0,0,%1\n" :
"=r" (res) :
"r" (ptr),
"m"(*(
TDS_UINT*)ptr));
224 # undef TDS_PUT_UA2LE
225 # undef TDS_PUT_UA4LE
229 __asm__ (
"sthbrx %1,0,%2\n" :
"=m" (*(
TDS_USMALLINT *)ptr) :
"r" (
data),
"r" (ptr));
234 __asm__ (
"stwbrx %1,0,%2\n" :
"=m" (*(
TDS_UINT *)ptr) :
"r" (
data),
"r" (ptr));
#define TDS_GET_UA4LE(ptr)
#define TDS_PUT_UA2LE(ptr, val)
#define TDS_GET_UA2LE(ptr)
#define TDS_PUT_UA4LE(ptr, val)
tds_sysdep_uint16_type TDS_USMALLINT
tds_sysdep_uint32_type TDS_UINT