summaryrefslogtreecommitdiffstats
path: root/memory/alloc/calloc.c
blob: cd272afe2821a2c8cb510c5c1bc684eff8ba593f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * Copyright (c) Jon Santmyer.
 * This source file is released under the LGPL Version 3 as detailed in
 * the LICENSE file provided in the following repository:
 * https://git.jonsantmyer.com/heap/
 * */

#include "malloc.h"
#include <string.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;

    /* Zero newly allocated memory as per spec.*/
    memset(ptr, 0, w * nmemb);
    return ptr;
}