summaryrefslogtreecommitdiff
path: root/web/nuweb/msdos/arena.c
diff options
context:
space:
mode:
Diffstat (limited to 'web/nuweb/msdos/arena.c')
-rw-r--r--web/nuweb/msdos/arena.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/web/nuweb/msdos/arena.c b/web/nuweb/msdos/arena.c
new file mode 100644
index 0000000000..ce0f738a3c
--- /dev/null
+++ b/web/nuweb/msdos/arena.c
@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+typedef struct chunk {
+ struct chunk *next;
+ char *limit;
+ char *avail;
+} Chunk;
+Chunk first = { NULL, NULL, NULL };
+Chunk *arena = &first;
+void *arena_getmem(n)
+ int n;
+{
+ char *q;
+ char *p = arena->avail;
+ n = (n + 3) & ~3; /* ensuring alignment to 4 bytes */
+ q = p + n;
+ if (q <= arena->limit) {
+ arena->avail = q;
+ return p;
+ }
+ {
+ Chunk *ap = arena;
+ Chunk *np = ap->next;
+ while (np) {
+ char *v = sizeof(Chunk) + (char *) np;
+ if (v + n <= np->limit) {
+ np->avail = v + n;
+ arena = np;
+ return v;
+ }
+ ap = np;
+ np = ap->next;
+ }
+ {
+ int m = n + 10000;
+ np = (Chunk *) malloc(m);
+ np->limit = m + (char *) np;
+ np->avail = n + sizeof(Chunk) + (char *) np;
+ np->next = NULL;
+ ap->next = np;
+ arena = np;
+ return sizeof(Chunk) + (char *) np;
+ }
+ }
+}
+void arena_free()
+{
+ arena = &first;
+}