summaryrefslogtreecommitdiffstats
path: root/calloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'calloc.c')
-rw-r--r--calloc.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/calloc.c b/calloc.c
new file mode 100644
index 0000000..d16da19
--- /dev/null
+++ b/calloc.c
@@ -0,0 +1,16 @@
+#include "malloc.h"
+#include <string.h>
+#include <errno.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;
+ if(errno != 0) return (void*)-1;
+
+ /* Zero newly allocated memory as per spec.*/
+ memset(ptr, 0, w * nmemb);
+ return ptr;
+}