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>
35WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
47#define _strtoui64 strtoull
51#define _strtoi64 strtoll
56static inline UINT32 _rotl(UINT32 value,
int shift)
58 return (value << shift) | (value >> (32 - shift));
64static inline UINT64 _rotl64(UINT64 value,
int shift)
66 return (value << shift) | (value >> (64 - shift));
72static inline UINT32 _rotr(UINT32 value,
int shift)
74 return (value >> shift) | (value << (32 - shift));
80static inline UINT64 _rotr64(UINT64 value,
int shift)
82 return (value >> shift) | (value << (64 - shift));
86#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2))
88#define _byteswap_ulong(_val) __builtin_bswap32(_val)
89#define _byteswap_uint64(_val) __builtin_bswap64(_val)
93WINPR_ATTR_NODISCARD
static inline UINT32 _byteswap_ulong(UINT32 _val)
95 return (((_val) >> 24) | (((_val)&0x00FF0000) >> 8) | (((_val)&0x0000FF00) << 8) |
99WINPR_ATTR_NODISCARD
static inline UINT64 _byteswap_uint64(UINT64 _val)
101 return (((_val) << 56) | (((_val) << 40) & 0xFF000000000000) |
102 (((_val) << 24) & 0xFF0000000000) | (((_val) << 8) & 0xFF00000000) |
103 (((_val) >> 8) & 0xFF000000) | (((_val) >> 24) & 0xFF0000) | (((_val) >> 40) & 0xFF00) |
109#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))
111#define _byteswap_ushort(_val) __builtin_bswap16(_val)
116static inline UINT16 _byteswap_ushort(UINT16 _val)
118 return WINPR_CXX_COMPAT_CAST(UINT16, ((_val) >> 8U) | ((_val) << 8U));
123#define CopyMemory(Destination, Source, Length) memcpy((Destination), (Source), (Length))
124#define MoveMemory(Destination, Source, Length) memmove((Destination), (Source), (Length))
125#define FillMemory(Destination, Length, Fill) memset((Destination), (Fill), (Length))
126#define ZeroMemory(Destination, Length) memset((Destination), 0, (Length))
133 WINPR_API PVOID SecureZeroMemory(PVOID ptr,
size_t cnt);
143WINPR_PRAGMA_DIAG_PUSH
144WINPR_PRAGMA_DIAG_IGNORED_RESERVED_ID_MACRO
146#ifndef _ERRNO_T_DEFINED
147#define _ERRNO_T_DEFINED
163 WINPR_API errno_t _itoa_s(
int value,
char* buffer,
size_t sizeInCharacters,
int radix);
168 WINPR_API errno_t memmove_s(
void* dest,
size_t numberOfElements,
const void* src,
size_t count);
171 WINPR_API errno_t wmemmove_s(WCHAR* dest,
size_t numberOfElements,
const WCHAR* src,
179#if !defined(_WIN32) || (defined(__MINGW32__) && !defined(_UCRT))
185#if defined(WINPR_MSVCR_ALIGNMENT_EMULATE)
186#define _aligned_malloc winpr_aligned_malloc
187#define _aligned_realloc winpr_aligned_realloc
188#define _aligned_recalloc winpr_aligned_recalloc
189#define _aligned_offset_malloc winpr_aligned_offset_malloc
190#define _aligned_offset_realloc winpr_aligned_offset_realloc
191#define _aligned_offset_recalloc winpr_aligned_offset_recalloc
192#define _aligned_msize winpr_aligned_msize
193#define _aligned_free winpr_aligned_free
201 WINPR_API
void winpr_aligned_free(
void* memblock);
203 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
204 WINPR_API
void* winpr_aligned_malloc(
size_t size,
size_t alignment);
206 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
207 WINPR_API
void* winpr_aligned_calloc(
size_t count,
size_t size,
size_t alignment);
209 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
210 WINPR_API
void* winpr_aligned_realloc(
void* memblock,
size_t size,
size_t alignment);
212 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
213 WINPR_API
void* winpr_aligned_recalloc(
void* memblock,
size_t num,
size_t size,
216 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
217 WINPR_API
void* winpr_aligned_offset_malloc(
size_t size,
size_t alignment,
size_t offset);
219 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
220 WINPR_API
void* winpr_aligned_offset_realloc(
void* memblock,
size_t size,
size_t alignment,
223 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
224 WINPR_API
void* winpr_aligned_offset_recalloc(
void* memblock,
size_t num,
size_t size,
225 size_t alignment,
size_t offset);
228 WINPR_API
size_t winpr_aligned_msize(
void* memblock,
size_t alignment,
size_t offset);
235#define winpr_aligned_malloc _aligned_malloc
236#define winpr_aligned_realloc _aligned_realloc
237#define winpr_aligned_recalloc _aligned_recalloc
238#define winpr_aligned_offset_malloc _aligned_offset_malloc
239#define winpr_aligned_offset_realloc _aligned_offset_realloc
240#define winpr_aligned_offset_recalloc _aligned_offset_recalloc
241#define winpr_aligned_msize _aligned_msize
242#define winpr_aligned_free _aligned_free
245#if defined(_WIN32) && (!defined(__MINGW32__) || defined(_UCRT))
246#define winpr_aligned_calloc(count, size, alignment) \
247 _aligned_recalloc(nullptr, count, size, alignment)