diff options
author | Jon Santmyer <jon@jonsantmyer.com> | 2024-04-19 16:11:24 -0400 |
---|---|---|
committer | Jon Santmyer <jon@jonsantmyer.com> | 2024-04-19 16:11:24 -0400 |
commit | 5b1b3bec3f25ea5fc1f48c269f300c4211a1bac7 (patch) | |
tree | d47b7693dd91a8dd08a5c7def418fd132a7032ac /calloc.c | |
download | heap-5b1b3bec3f25ea5fc1f48c269f300c4211a1bac7.tar.gz heap-5b1b3bec3f25ea5fc1f48c269f300c4211a1bac7.tar.bz2 heap-5b1b3bec3f25ea5fc1f48c269f300c4211a1bac7.zip |
initial commit; mostly documented.
Diffstat (limited to 'calloc.c')
-rw-r--r-- | calloc.c | 16 |
1 files changed, 16 insertions, 0 deletions
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 <string.h> +#include <errno.h> + +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; +} |