summaryrefslogtreecommitdiff
path: root/amiga/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'amiga/alloc.c')
-rwxr-xr-xamiga/alloc.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/amiga/alloc.c b/amiga/alloc.c
new file mode 100755
index 000000000..062efab6c
--- /dev/null
+++ b/amiga/alloc.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <proto/exec.h>
+
+#ifdef AMIGA_NETSURF_REPLACE_ALLOC
+#define nsa_malloc malloc
+#define nsa_calloc calloc
+#define nsa_realloc realloc
+#define nsa_free free
+#endif
+
+void nsa_free(void *p) {
+ if(p == NULL) return;
+ UBYTE *mem = p - 4;
+ FreeVec(mem);
+}
+void *nsa_malloc(size_t s) {
+ UBYTE *mem = AllocVec(s + 4, MEMF_PRIVATE);
+ *mem = s;
+ return mem + 4;
+}
+void *nsa_calloc(size_t nelem, size_t nsize) {
+ UBYTE *mem = AllocVec((nelem * nsize) + 4, MEMF_PRIVATE | MEMF_CLEAR);
+ *mem = (nelem * nsize);
+ return mem + 4;
+}
+void *nsa_realloc(void *p, size_t s) {
+ void *newptr;
+ ULONG old_size = *((UBYTE *)p - 4);
+ newptr = nsa_malloc(s);
+ memcpy(newptr, p, old_size);
+ nsa_free(p);
+ return newptr;
+}