shithub: scc

ref: f3d06fb5d6fc6d3540f693f883c90c50141fc6f1
dir: /lib/c/calloc.c/

View raw version
#include <stdlib.h>
#include <string.h>

void *
calloc(size_t nmemb, size_t size)
{
	size_t nbytes;
	void *mem;

	if (!nmemb || !size || nmemb > (size_t)-1/size)
                return NULL;

	nbytes = nmemb * size;
	if ((mem = malloc(nbytes)) == NULL)
		return NULL;
	return memset(mem, 0, nbytes);
}