From 5b1b3bec3f25ea5fc1f48c269f300c4211a1bac7 Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Fri, 19 Apr 2024 16:11:24 -0400 Subject: initial commit; mostly documented. --- calloc.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 calloc.c (limited to 'calloc.c') diff --git a/calloc.c b/calloc.c new file mode 100644 index 0000000..d16da19 --- /dev/null +++ b/calloc.c @@ -0,0 +1,16 @@ +#include "malloc.h" +#include +#include + +void* +__calloc_impl(heap_cache_t *cache, size_t nmemb, size_t w) +{ + w = REALW(w); + void *ptr = __malloc_impl(cache, w * nmemb); + if(ptr == NULL) return NULL; + if(errno != 0) return (void*)-1; + + /* Zero newly allocated memory as per spec.*/ + memset(ptr, 0, w * nmemb); + return ptr; +} -- cgit v1.2.1