summaryrefslogtreecommitdiffstats
path: root/calloc.c
blob: d16da19c3e9c24013f1692f56edf8049f7864329 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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;
}