lib: Add obvious definition for calloc

The calloc() function is useful in addition to malloc and friends, so
add the obvious definition.

Change-Id: I57a568e323344a97b35014b7b8bec16adc2fd720
Signed-off-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/51949
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Tim Wawrzynczak
2021-03-30 11:49:14 -06:00
committed by Patrick Georgi
parent 8aedb34501
commit c556dffe98
3 changed files with 34 additions and 1 deletions

View File

@ -1,5 +1,6 @@
#include <stdlib.h>
#include <console/console.h>
#include <stdlib.h>
#include <string.h>
#if CONFIG(DEBUG_MALLOC)
#define MALLOCDBG(x...) printk(BIOS_SPEW, x)
@ -54,6 +55,15 @@ void *malloc(size_t size)
return memalign(sizeof(u64), size);
}
void *calloc(size_t nitems, size_t size)
{
void *p = malloc(nitems * size);
if (p)
memset(p, 0, nitems * size);
return p;
}
void free(void *ptr)
{
if (ptr == NULL)