27 #include <winpr/platform.h>
28 #include <winpr/winpr.h>
30 #include <winpr/spec.h>
31 #include <winpr/string.h>
33 WINPR_PRAGMA_DIAG_PUSH
34 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
45 #define _strtoui64 strtoull
49 #define _strtoi64 strtoll
53 static INLINE UINT32 _rotl(UINT32 value,
int shift)
55 return (value << shift) | (value >> (32 - shift));
60 static INLINE UINT64 _rotl64(UINT64 value,
int shift)
62 return (value << shift) | (value >> (64 - shift));
67 static INLINE UINT32 _rotr(UINT32 value,
int shift)
69 return (value >> shift) | (value << (32 - shift));
74 static INLINE UINT64 _rotr64(UINT64 value,
int shift)
76 return (value >> shift) | (value << (64 - shift));
80 #if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2))
82 #define _byteswap_ulong(_val) __builtin_bswap32(_val)
83 #define _byteswap_uint64(_val) __builtin_bswap64(_val)
87 static INLINE UINT32 _byteswap_ulong(UINT32 _val)
89 return (((_val) >> 24) | (((_val)&0x00FF0000) >> 8) | (((_val)&0x0000FF00) << 8) |
93 static INLINE UINT64 _byteswap_uint64(UINT64 _val)
95 return (((_val) << 56) | (((_val) << 40) & 0xFF000000000000) |
96 (((_val) << 24) & 0xFF0000000000) | (((_val) << 8) & 0xFF00000000) |
97 (((_val) >> 8) & 0xFF000000) | (((_val) >> 24) & 0xFF0000) | (((_val) >> 40) & 0xFF00) |
103 #if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))
105 #define _byteswap_ushort(_val) __builtin_bswap16(_val)
109 static INLINE UINT16 _byteswap_ushort(UINT16 _val)
112 #define winpr_byteswap_cast(t, val) static_cast<t>(val)
114 #define winpr_byteswap_cast(t, val) (t)(val)
116 return winpr_byteswap_cast(UINT16, ((_val) >> 8U) | ((_val) << 8U));
117 #undef winpr_byteswap_cast
122 #define CopyMemory(Destination, Source, Length) memcpy((Destination), (Source), (Length))
123 #define MoveMemory(Destination, Source, Length) memmove((Destination), (Source), (Length))
124 #define FillMemory(Destination, Length, Fill) memset((Destination), (Fill), (Length))
125 #define ZeroMemory(Destination, Length) memset((Destination), 0, (Length))
132 WINPR_API PVOID SecureZeroMemory(PVOID ptr,
size_t cnt);
142 WINPR_PRAGMA_DIAG_PUSH
143 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_ID_MACRO
145 #ifndef _ERRNO_T_DEFINED
146 #define _ERRNO_T_DEFINED
150 WINPR_PRAGMA_DIAG_POP
161 WINPR_API errno_t _itoa_s(
int value,
char* buffer,
size_t sizeInCharacters,
int radix);
165 WINPR_API errno_t memmove_s(
void* dest,
size_t numberOfElements,
const void* src,
size_t count);
166 WINPR_API errno_t wmemmove_s(WCHAR* dest,
size_t numberOfElements,
const WCHAR* src,
174 #if !defined(_WIN32) || (defined(__MINGW32__) && !defined(_UCRT))
180 #if defined(WINPR_MSVCR_ALIGNMENT_EMULATE)
181 #define _aligned_malloc winpr_aligned_malloc
182 #define _aligned_realloc winpr_aligned_realloc
183 #define _aligned_recalloc winpr_aligned_recalloc
184 #define _aligned_offset_malloc winpr_aligned_offset_malloc
185 #define _aligned_offset_realloc winpr_aligned_offset_realloc
186 #define _aligned_offset_recalloc winpr_aligned_offset_recalloc
187 #define _aligned_msize winpr_aligned_msize
188 #define _aligned_free winpr_aligned_free
196 WINPR_API
void winpr_aligned_free(
void* memblock);
198 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
199 WINPR_API
void* winpr_aligned_malloc(
size_t size,
size_t alignment);
201 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
202 WINPR_API
void* winpr_aligned_calloc(
size_t count,
size_t size,
size_t alignment);
204 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
205 WINPR_API
void* winpr_aligned_realloc(
void* memblock,
size_t size,
size_t alignment);
207 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
208 WINPR_API
void* winpr_aligned_recalloc(
void* memblock,
size_t num,
size_t size,
211 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
212 WINPR_API
void* winpr_aligned_offset_malloc(
size_t size,
size_t alignment,
size_t offset);
214 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
215 WINPR_API
void* winpr_aligned_offset_realloc(
void* memblock,
size_t size,
size_t alignment,
218 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
219 WINPR_API
void* winpr_aligned_offset_recalloc(
void* memblock,
size_t num,
size_t size,
220 size_t alignment,
size_t offset);
222 WINPR_API
size_t winpr_aligned_msize(
void* memblock,
size_t alignment,
size_t offset);
229 #define winpr_aligned_malloc _aligned_malloc
230 #define winpr_aligned_realloc _aligned_realloc
231 #define winpr_aligned_recalloc _aligned_recalloc
232 #define winpr_aligned_offset_malloc _aligned_offset_malloc
233 #define winpr_aligned_offset_realloc _aligned_offset_realloc
234 #define winpr_aligned_offset_recalloc _aligned_offset_recalloc
235 #define winpr_aligned_msize _aligned_msize
236 #define winpr_aligned_free _aligned_free
239 #if defined(_WIN32) && (!defined(__MINGW32__) || defined(_UCRT))
240 #define winpr_aligned_calloc(count, size, alignment) _aligned_recalloc(NULL, count, size, alignment)
243 WINPR_PRAGMA_DIAG_POP