summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-06-30 16:09:23 -0400
committerJakob Kaivo <jkk@ung.org>2020-06-30 16:09:23 -0400
commit388f3dfd269368b26990f86d12ea6ab1c4b7c4e6 (patch)
treedc662d2cc8bd2da650bf3554764ab8534c2d1442 /test
parent30779981519a03506e515851a760a1f1f5a98a23 (diff)
add optional macros to directly provide the <stdlib.h> interface
Diffstat (limited to 'test')
-rw-r--r--test/macros.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/macros.c b/test/macros.c
new file mode 100644
index 0000000..3c7a35a
--- /dev/null
+++ b/test/macros.c
@@ -0,0 +1,25 @@
+#define _POSIX_C_SOURCE 200809L
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#define MA_OVERRIDE_STDLIB
+#include "mapalloc.h"
+
+int main(void)
+{
+ const char buf[] = "THIS IS A CONSTANT STRING";
+
+ char *ptr = realloc(NULL, sizeof(buf));
+ memcpy(ptr, buf, sizeof(buf));
+ printf("%p: %s\n", ptr, ptr);
+
+ ptr = realloc(ptr, sizeof(buf) * 2);
+ memcpy(ptr + sizeof(buf) - 1, buf, sizeof(buf));
+ printf("%p: %s\n", ptr, ptr);
+
+ ptr = realloc(ptr, sizeof(buf) * sysconf(_SC_PAGESIZE));
+ memcpy(ptr + (2 * sizeof(buf)) - 2, buf, sizeof(buf));
+ printf("%p: %s\n", ptr, ptr);
+}