diff --git a/sdk/lib/crt/msvcrtex.cmake b/sdk/lib/crt/msvcrtex.cmake index ff74ebb68b3..ddf1f4722d2 100644 --- a/sdk/lib/crt/msvcrtex.cmake +++ b/sdk/lib/crt/msvcrtex.cmake @@ -8,7 +8,8 @@ list(APPEND MSVCRTEX_SOURCE misc/isblank.c misc/iswblank.c misc/ofmt_stub.c - stdio/acrt_iob_func.c) + stdio/acrt_iob_func.c + recalloc.c) if(DLL_EXPORT_VERSION LESS 0x600) list(APPEND MSVCRTEX_SOURCE diff --git a/sdk/lib/crt/recalloc.c b/sdk/lib/crt/recalloc.c new file mode 100644 index 00000000000..686144af47e --- /dev/null +++ b/sdk/lib/crt/recalloc.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +void* __cdecl recalloc(void *mem, size_t num, size_t size) +{ + size_t old_size; + void *ret; + + if(!mem) + return calloc(num, size); + + size = num*size; + old_size = _msize(mem); + + ret = realloc(mem, size); + if(!ret) { + *_errno() = ENOMEM; + return NULL; + } + + if(size>old_size) + memset((unsigned char*)ret+old_size, 0, size-old_size); + return ret; +} + +#ifdef _WIN64 +void* __imp__recalloc = recalloc; +#else +void* _imp___recalloc = recalloc; +#endif