Skip to content

Commit b6cb535

Browse files
committed
[MSVCRTEX] Add recalloc. CORE-20596
1 parent 360b579 commit b6cb535

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎sdk/lib/crt/msvcrtex.cmake‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ list(APPEND MSVCRTEX_SOURCE
88
misc/isblank.c
99
misc/iswblank.c
1010
misc/ofmt_stub.c
11-
stdio/acrt_iob_func.c)
11+
stdio/acrt_iob_func.c
12+
recalloc.c)
1213

1314
if(DLL_EXPORT_VERSION LESS 0x600)
1415
list(APPEND MSVCRTEX_SOURCE

‎sdk/lib/crt/recalloc.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stdlib.h>
2+
#include <string.h>
3+
#include <errno.h>
4+
#include <malloc.h>
5+
6+
void* __cdecl recalloc(void *mem, size_t num, size_t size)
7+
{
8+
size_t old_size;
9+
void *ret;
10+
11+
if(!mem)
12+
return calloc(num, size);
13+
14+
size = num*size;
15+
old_size = _msize(mem);
16+
17+
ret = realloc(mem, size);
18+
if(!ret) {
19+
*_errno() = ENOMEM;
20+
return NULL;
21+
}
22+
23+
if(size>old_size)
24+
memset((unsigned char*)ret+old_size, 0, size-old_size);
25+
return ret;
26+
}
27+
28+
#ifdef _WIN64
29+
void* __imp__recalloc = recalloc;
30+
#else
31+
void* _imp___recalloc = recalloc;
32+
#endif

0 commit comments

Comments
 (0)