calloc.c - scc - simple c99 compiler
 (HTM) git clone git://git.simple-cc.org/scc
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
       calloc.c (335B)
       ---
            1 #include <stdlib.h>
            2 #include <string.h>
            3 #include <stdint.h>
            4 
            5 #undef calloc
            6 
            7 void *
            8 calloc(size_t nmemb, size_t size)
            9 {
           10         size_t nbytes;
           11         void *mem;
           12 
           13         if (!nmemb || !size || nmemb > SIZE_MAX/size)
           14                 return NULL;
           15 
           16         nbytes = nmemb * size;
           17         if ((mem = malloc(nbytes)) == NULL)
           18                 return NULL;
           19         return memset(mem, 0, nbytes);
           20 }