summaryrefslogtreecommitdiff
path: root/src/stdlib/calloc.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-02-08 18:42:39 -0500
committerJakob Kaivo <jkk@ung.org>2019-02-08 18:42:39 -0500
commit7ef8a7379f7f7d09e71ccae2a0b688c3cd80423f (patch)
tree092ab0aed1769117fd7b28b8592f6f96b0e0d5af /src/stdlib/calloc.c
parent6acf19370e8adff79cd83b257d3f04aeaf2a59dd (diff)
merge sources into single tree
Diffstat (limited to 'src/stdlib/calloc.c')
-rw-r--r--src/stdlib/calloc.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/stdlib/calloc.c b/src/stdlib/calloc.c
new file mode 100644
index 00000000..aeed4aef
--- /dev/null
+++ b/src/stdlib/calloc.c
@@ -0,0 +1,33 @@
+#include <stdlib.h>
+#include "string.h"
+
+/** allocate and initialize memory **/
+
+void * calloc(size_t nmemb, size_t size)
+{
+ void *p = NULL;
+
+ if (nmemb == 0 || size == 0) {
+ return NULL;
+ }
+
+ p = realloc(NULL, size * nmemb);
+ if (p != NULL) {
+ memset(p, 0, size * nmemb);
+ }
+
+ return p;
+}
+
+/***
+allocates an array of ARGUMENT(nmemb) elements, each of which
+are ARGUMENT(size) bytes, and sets all their bits to 0.
+***/
+
+/*
+UNSPECIFIED(The order and contiguity of space allocated by success calls)
+IMPLEMENTATION(What is returned if ARGUMENT(nmemb) or ARGUMENT(size) is 0)
+RETURN_FAILURE(CONSTANT(NULL))
+RETURN_SUCCESS(a pointer to the newly allocated memory)
+STDC(1)
+*/