summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mapalloc.c35
-rw-r--r--src/mapalloc.h11
2 files changed, 46 insertions, 0 deletions
diff --git a/src/mapalloc.c b/src/mapalloc.c
new file mode 100644
index 0000000..bde39f9
--- /dev/null
+++ b/src/mapalloc.c
@@ -0,0 +1,35 @@
+#define _POSIX_C_SOURCE 200809L
+#include <sys/mman.h>
+#include <string.h>
+
+#include "mapalloc.h"
+
+void *map_calloc(size_t nelem, size_t elsize)
+{
+ size_t n = nelem * elsize;
+ if (n < nelem || n < elsize) {
+ /* overflow */
+ return NULL;
+ }
+ void *ptr = map_malloc(n);
+ memset(ptr, 0, n);
+ return ptr;
+}
+
+void *map_malloc(size_t n)
+{
+}
+
+void *map_realloc(void *ptr, size_t n)
+{
+ if (ptr == NULL) {
+ return map_malloc(n);
+ }
+}
+
+void map_free(void *ptr)
+{
+ if (ptr == NULL) {
+ return;
+ }
+}
diff --git a/src/mapalloc.h b/src/mapalloc.h
new file mode 100644
index 0000000..f4a4434
--- /dev/null
+++ b/src/mapalloc.h
@@ -0,0 +1,11 @@
+#ifndef MAPALLOC_H
+#define MAPALLOC_H
+
+#include <stddef.h> /* for the definition of size_t */
+
+void *map_malloc(size_t n);
+void *map_calloc(size_t nelem, size_t elsize);
+void *map_realloc(void *ptr, size_t n);
+void map_free(void *ptr);
+
+#endif