summary refs log tree commit diff
diff options
context:
space:
mode:
authorWormHeamer2025-02-28 20:16:41 -0500
committerWormHeamer2025-02-28 20:16:41 -0500
commit5a879792ccc2cb7b148d4d6055b98edc7c7b7675 (patch)
tree675a95cd8038bea0f1dcf2da7ef4c22f156fe200
parente80525a7785819d1b5453d3a642a98ac0ec5c52d (diff)
have just a single ZONE_BACKEND definition
-rw-r--r--zone.h22
1 files changed, 18 insertions, 4 deletions
diff --git a/zone.h b/zone.h
index bce6796..def53d0 100644
--- a/zone.h
+++ b/zone.h
@@ -3,6 +3,9 @@
 
 #include <stdint.h>
 
+#define ZONE_USE_MALLOC 0
+#define ZONE_USE_MMAP   1
+
 typedef struct ZoneFrame ZoneFrame;
 struct ZoneFrame {
 	ZoneFrame *prev, *next;
@@ -32,11 +35,20 @@ char *zn_strdup(Zone *z, const char *s);
 #ifdef ZONE_IMPL
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include "zone.h"
 
-#if defined(ZONE_USE_MMAP)
+#ifndef ZONE_BACKEND
+	#ifdef __unix__
+		#define ZONE_BACKEND ZONE_USE_MMAP
+	#else
+		#define ZONE_BACKEND ZONE_USE_MALLOC
+	#endif
+#endif
+
+#if ZONE_BACKEND == ZONE_USE_MMAP
 
 	#include <sys/mman.h>
 	#include <unistd.h>
@@ -54,9 +66,7 @@ char *zn_strdup(Zone *z, const char *s);
 		munmap(zf, sizeof *zf + zf->capacity * sizeof(uintptr_t));
 	}
 
-#else
-
-	#include <stdlib.h>
+#elif ZONE_BACKEND == ZONE_USE_MALLOC
 
 	#define ZONE_CAPACITY 1024
 	static ZoneFrame *zn_zf_allocate(size_t capacity) {
@@ -71,6 +81,10 @@ char *zn_strdup(Zone *z, const char *s);
 		free(zf);
 	}
 
+#else
+
+	#error "unknown or unsupported zone backend"
+
 #endif
 
 static ZoneFrame *zn_zf_new(size_t capacity) {