scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

calloc.c (302B)


      1 #include <stdlib.h>
      2 #include <string.h>
      3 
      4 void *
      5 calloc(size_t nmemb, size_t size)
      6 {
      7 	size_t nbytes;
      8 	void *mem;
      9 
     10 	if (!nmemb || !size || nmemb > (size_t)-1/size)
     11                 return NULL;
     12 
     13 	nbytes = nmemb * size;
     14 	if ((mem = malloc(nbytes)) == NULL)
     15 		return NULL;
     16 	return memset(mem, 0, nbytes);
     17 }