27 #include <winpr/cast.h>
28 #include <winpr/platform.h>
29 #include <winpr/winpr.h>
31 #include <winpr/spec.h>
32 #include <winpr/string.h>
34 WINPR_PRAGMA_DIAG_PUSH
35 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
46 #define _strtoui64 strtoull
50 #define _strtoi64 strtoll
54 static INLINE UINT32 _rotl(UINT32 value,
int shift)
56 return (value << shift) | (value >> (32 - shift));
61 static INLINE UINT64 _rotl64(UINT64 value,
int shift)
63 return (value << shift) | (value >> (64 - shift));
68 static INLINE UINT32 _rotr(UINT32 value,
int shift)
70 return (value >> shift) | (value << (32 - shift));
75 static INLINE UINT64 _rotr64(UINT64 value,
int shift)
77 return (value >> shift) | (value << (64 - shift));
81 #if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2))
83 #define _byteswap_ulong(_val) __builtin_bswap32(_val)
84 #define _byteswap_uint64(_val) __builtin_bswap64(_val)
88 static INLINE UINT32 _byteswap_ulong(UINT32 _val)
90 return (((_val) >> 24) | (((_val)&0x00FF0000) >> 8) | (((_val)&0x0000FF00) << 8) |
94 static INLINE UINT64 _byteswap_uint64(UINT64 _val)
96 return (((_val) << 56) | (((_val) << 40) & 0xFF000000000000) |
97 (((_val) << 24) & 0xFF0000000000) | (((_val) << 8) & 0xFF00000000) |
98 (((_val) >> 8) & 0xFF000000) | (((_val) >> 24) & 0xFF0000) | (((_val) >> 40) & 0xFF00) |
104 #if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))
106 #define _byteswap_ushort(_val) __builtin_bswap16(_val)
110 static INLINE UINT16 _byteswap_ushort(UINT16 _val)
112 return WINPR_CXX_COMPAT_CAST(UINT16, ((_val) >> 8U) | ((_val) << 8U));
117 #define CopyMemory(Destination, Source, Length) memcpy((Destination), (Source), (Length))
118 #define MoveMemory(Destination, Source, Length) memmove((Destination), (Source), (Length))
119 #define FillMemory(Destination, Length, Fill) memset((Destination), (Fill), (Length))
120 #define ZeroMemory(Destination, Length) memset((Destination), 0, (Length))
127 WINPR_API PVOID SecureZeroMemory(PVOID ptr,
size_t cnt);
137 WINPR_PRAGMA_DIAG_PUSH
138 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_ID_MACRO
140 #ifndef _ERRNO_T_DEFINED
141 #define _ERRNO_T_DEFINED
145 WINPR_PRAGMA_DIAG_POP
156 WINPR_API errno_t _itoa_s(
int value,
char* buffer,
size_t sizeInCharacters,
int radix);
160 WINPR_API errno_t memmove_s(
void* dest,
size_t numberOfElements,
const void* src,
size_t count);
161 WINPR_API errno_t wmemmove_s(WCHAR* dest,
size_t numberOfElements,
const WCHAR* src,
169 #if !defined(_WIN32) || (defined(__MINGW32__) && !defined(_UCRT))
175 #if defined(WINPR_MSVCR_ALIGNMENT_EMULATE)
176 #define _aligned_malloc winpr_aligned_malloc
177 #define _aligned_realloc winpr_aligned_realloc
178 #define _aligned_recalloc winpr_aligned_recalloc
179 #define _aligned_offset_malloc winpr_aligned_offset_malloc
180 #define _aligned_offset_realloc winpr_aligned_offset_realloc
181 #define _aligned_offset_recalloc winpr_aligned_offset_recalloc
182 #define _aligned_msize winpr_aligned_msize
183 #define _aligned_free winpr_aligned_free
191 WINPR_API
void winpr_aligned_free(
void* memblock);
193 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
194 WINPR_API
void* winpr_aligned_malloc(
size_t size,
size_t alignment);
196 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
197 WINPR_API
void* winpr_aligned_calloc(
size_t count,
size_t size,
size_t alignment);
199 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
200 WINPR_API
void* winpr_aligned_realloc(
void* memblock,
size_t size,
size_t alignment);
202 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
203 WINPR_API
void* winpr_aligned_recalloc(
void* memblock,
size_t num,
size_t size,
206 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
207 WINPR_API
void* winpr_aligned_offset_malloc(
size_t size,
size_t alignment,
size_t offset);
209 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
210 WINPR_API
void* winpr_aligned_offset_realloc(
void* memblock,
size_t size,
size_t alignment,
213 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
214 WINPR_API
void* winpr_aligned_offset_recalloc(
void* memblock,
size_t num,
size_t size,
215 size_t alignment,
size_t offset);
217 WINPR_API
size_t winpr_aligned_msize(
void* memblock,
size_t alignment,
size_t offset);
224 #define winpr_aligned_malloc _aligned_malloc
225 #define winpr_aligned_realloc _aligned_realloc
226 #define winpr_aligned_recalloc _aligned_recalloc
227 #define winpr_aligned_offset_malloc _aligned_offset_malloc
228 #define winpr_aligned_offset_realloc _aligned_offset_realloc
229 #define winpr_aligned_offset_recalloc _aligned_offset_recalloc
230 #define winpr_aligned_msize _aligned_msize
231 #define winpr_aligned_free _aligned_free
234 #if defined(_WIN32) && (!defined(__MINGW32__) || defined(_UCRT))
235 #define winpr_aligned_calloc(count, size, alignment) _aligned_recalloc(NULL, count, size, alignment)
238 WINPR_PRAGMA_DIAG_POP