fxlibc/src/libc/stdlib/calloc.c

15 lines
260 B
C
Raw Normal View History

2021-05-09 17:34:00 +02:00
#include <stdlib.h>
#include <string.h>
2020-09-17 19:27:01 +02:00
void *calloc(size_t nmemb, size_t size)
{
unsigned int total_size;
2020-09-17 19:27:01 +02:00
if(__builtin_umul_overflow(nmemb, size, &total_size))
return NULL;
2020-09-17 19:27:01 +02:00
void *mem = malloc(total_size);
if(mem) memset(mem, 0, size);
return mem;
2020-09-17 19:27:01 +02:00
}