summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-06-29 12:20:31 -0400
committerJakob Kaivo <jkk@ung.org>2020-06-29 12:20:31 -0400
commitcda4527cefc55f4d9ade17cca717f60214b82062 (patch)
tree41618b1374e313ed1749ceeaae4b5f2c583c860a /src
parentf5b80adc878ada4b3267c2ea0a060193af64d9c3 (diff)
outline functions
Diffstat (limited to 'src')
-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