summaryrefslogtreecommitdiff
path: root/fitz/base_memory.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2009-02-28 13:00:34 +0100
committerTor Andersson <tor@ghostscript.com>2009-02-28 13:00:34 +0100
commitf744dace3f0f91b8505979bf244453c9ec713b4b (patch)
tree86fed467944886a17d4d22038990a8fd8d2e3be8 /fitz/base_memory.c
parentd0631f32c95f656d30c90d28c15a56b09fcc86ee (diff)
downloadmupdf-f744dace3f0f91b8505979bf244453c9ec713b4b.tar.xz
Moved Fitz files into one directory.
Diffstat (limited to 'fitz/base_memory.c')
-rw-r--r--fitz/base_memory.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/fitz/base_memory.c b/fitz/base_memory.c
new file mode 100644
index 00000000..8c2c0249
--- /dev/null
+++ b/fitz/base_memory.c
@@ -0,0 +1,79 @@
+#include "fitz-base.h"
+
+/* Make this thread local storage if you wish. */
+
+static void *stdmalloc(fz_memorycontext *mem, int n)
+{
+ return malloc(n);
+}
+
+static void *stdrealloc(fz_memorycontext *mem, void *p, int n)
+{
+ return realloc(p, n);
+}
+
+static void stdfree(fz_memorycontext *mem, void *p)
+{
+ free(p);
+}
+
+static fz_memorycontext defmem = { stdmalloc, stdrealloc, stdfree };
+static fz_memorycontext *curmem = &defmem;
+
+fz_error fz_koutofmem = {
+ {"out of memory"},
+ {"<internal>"},
+ {"<internal>"},
+ 0,
+ nil
+};
+
+fz_memorycontext *
+fz_currentmemorycontext()
+{
+ return curmem;
+}
+
+void
+fz_setmemorycontext(fz_memorycontext *mem)
+{
+ curmem = mem;
+}
+
+void *
+fz_malloc(int n)
+{
+ fz_memorycontext *mem = fz_currentmemorycontext();
+ void *p = mem->malloc(mem, n);
+ if (!p)
+ fz_warn("cannot malloc %d bytes", n);
+ return p;
+}
+
+void *
+fz_realloc(void *p, int n)
+{
+ fz_memorycontext *mem = fz_currentmemorycontext();
+ void *np = mem->realloc(mem, p, n);
+ if (np == nil)
+ fz_warn("cannot realloc %d bytes", n);
+ return np;
+}
+
+void
+fz_free(void *p)
+{
+ fz_memorycontext *mem = fz_currentmemorycontext();
+ mem->free(mem, p);
+}
+
+char *
+fz_strdup(char *s)
+{
+ int len = strlen(s);
+ char *ns = fz_malloc(len + 1);
+ if (ns)
+ strcpy(ns, s);
+ return ns;
+}
+