scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

calloc.c (316B)


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