aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_bithelpers.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/mhd_bithelpers.h')
-rw-r--r--src/microhttpd/mhd_bithelpers.h32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/microhttpd/mhd_bithelpers.h b/src/microhttpd/mhd_bithelpers.h
index 12e1a569..9bd2df79 100644
--- a/src/microhttpd/mhd_bithelpers.h
+++ b/src/microhttpd/mhd_bithelpers.h
@@ -99,6 +99,17 @@
99 * put native-endian 64-bit value64 to addr 99 * put native-endian 64-bit value64 to addr
100 * in little-endian mode. 100 * in little-endian mode.
101 */ 101 */
102/* Slow version that works with unaligned addr and with any bytes order */
103#define _MHD_PUT_64BIT_LE_SLOW(addr, value64) do { \
104 ((uint8_t*) (addr))[0] = (uint8_t) ((uint64_t) (value64)); \
105 ((uint8_t*) (addr))[1] = (uint8_t) (((uint64_t) (value64)) >> 8); \
106 ((uint8_t*) (addr))[2] = (uint8_t) (((uint64_t) (value64)) >> 16); \
107 ((uint8_t*) (addr))[3] = (uint8_t) (((uint64_t) (value64)) >> 24); \
108 ((uint8_t*) (addr))[4] = (uint8_t) (((uint64_t) (value64)) >> 32); \
109 ((uint8_t*) (addr))[5] = (uint8_t) (((uint64_t) (value64)) >> 40); \
110 ((uint8_t*) (addr))[6] = (uint8_t) (((uint64_t) (value64)) >> 48); \
111 ((uint8_t*) (addr))[7] = (uint8_t) (((uint64_t) (value64)) >> 56); \
112} while (0)
102#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN 113#if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
103#define _MHD_PUT_64BIT_LE(addr, value64) \ 114#define _MHD_PUT_64BIT_LE(addr, value64) \
104 ((*(uint64_t*) (addr)) = (uint64_t) (value64)) 115 ((*(uint64_t*) (addr)) = (uint64_t) (value64))
@@ -117,8 +128,23 @@
117 ((uint8_t*) (addr))[6] = (uint8_t) (((uint64_t) (value64)) >> 48); \ 128 ((uint8_t*) (addr))[6] = (uint8_t) (((uint64_t) (value64)) >> 48); \
118 ((uint8_t*) (addr))[7] = (uint8_t) (((uint64_t) (value64)) >> 56); \ 129 ((uint8_t*) (addr))[7] = (uint8_t) (((uint64_t) (value64)) >> 56); \
119} while (0) 130} while (0)
131/* Indicate that _MHD_PUT_64BIT_LE does not need aligned pointer */
132#define _MHD_PUT_64BIT_LE_UNALIGNED 1
120#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ 133#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
121 134
135/* Put result safely to unaligned address */
136_MHD_static_inline void
137_MHD_PUT_64BIT_LE_SAFE (void *dst, uint64_t value)
138{
139#ifndef _MHD_PUT_64BIT_LE_UNALIGNED
140 if (0 != ((uintptr_t) dst) % (_MHD_UINT64_ALIGN))
141 _MHD_PUT_64BIT_LE_SLOW (dst, value);
142 else
143#endif /* ! _MHD_PUT_64BIT_BE_UNALIGNED */
144 _MHD_PUT_64BIT_LE (dst, value);
145}
146
147
122/* _MHD_PUT_32BIT_LE (addr, value32) 148/* _MHD_PUT_32BIT_LE (addr, value32)
123 * put native-endian 32-bit value32 to addr 149 * put native-endian 32-bit value32 to addr
124 * in little-endian mode. 150 * in little-endian mode.
@@ -137,6 +163,8 @@
137 ((uint8_t*) (addr))[2] = (uint8_t) (((uint32_t) (value32)) >> 16); \ 163 ((uint8_t*) (addr))[2] = (uint8_t) (((uint32_t) (value32)) >> 16); \
138 ((uint8_t*) (addr))[3] = (uint8_t) (((uint32_t) (value32)) >> 24); \ 164 ((uint8_t*) (addr))[3] = (uint8_t) (((uint32_t) (value32)) >> 24); \
139} while (0) 165} while (0)
166/* Indicate that _MHD_PUT_32BIT_LE does not need aligned pointer */
167#define _MHD_PUT_32BIT_LE_UNALIGNED 1
140#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ 168#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
141 169
142/* _MHD_GET_32BIT_LE (addr) 170/* _MHD_GET_32BIT_LE (addr)
@@ -156,6 +184,8 @@
156 | (((uint32_t) (((const uint8_t*) addr)[1])) << 8) \ 184 | (((uint32_t) (((const uint8_t*) addr)[1])) << 8) \
157 | (((uint32_t) (((const uint8_t*) addr)[2])) << 16) \ 185 | (((uint32_t) (((const uint8_t*) addr)[2])) << 16) \
158 | (((uint32_t) (((const uint8_t*) addr)[3])) << 24) ) 186 | (((uint32_t) (((const uint8_t*) addr)[3])) << 24) )
187/* Indicate that _MHD_GET_32BIT_LE does not need aligned pointer */
188#define _MHD_GET_32BIT_LE_UNALIGNED 1
159#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */ 189#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
160 190
161 191
@@ -195,7 +225,7 @@ _MHD_PUT_64BIT_BE_SAFE (void *dst, uint64_t value)
195 if (0 != ((uintptr_t) dst) % (_MHD_UINT64_ALIGN)) 225 if (0 != ((uintptr_t) dst) % (_MHD_UINT64_ALIGN))
196 _MHD_PUT_64BIT_BE_SLOW (dst, value); 226 _MHD_PUT_64BIT_BE_SLOW (dst, value);
197 else 227 else
198#endif /* _MHD_BYTE_ORDER_IS_BIG_OR_LITTLE_ENDIAN */ 228#endif /* ! _MHD_PUT_64BIT_BE_UNALIGNED */
199 _MHD_PUT_64BIT_BE (dst, value); 229 _MHD_PUT_64BIT_BE (dst, value);
200} 230}
201 231