summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/stdlib.h1
-rw-r--r--src/lib/malloc.c12
2 files changed, 12 insertions, 1 deletions
diff --git a/src/include/stdlib.h b/src/include/stdlib.h
index f6369bf0f4..8636ea45c9 100644
--- a/src/include/stdlib.h
+++ b/src/include/stdlib.h
@@ -5,6 +5,7 @@
void *memalign(size_t boundary, size_t size);
void *malloc(size_t size);
+void *calloc(size_t nitems, size_t size);
void free(void *ptr);
#endif /* STDLIB_H */
diff --git a/src/lib/malloc.c b/src/lib/malloc.c
index cd86f99f0b..7d787d631e 100644
--- a/src/lib/malloc.c
+++ b/src/lib/malloc.c
@@ -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)