Delete all Trailing spaces in code.
[reactos.git] / rosapps / smartpdf / fitz / base / base_memory.c
1 #include "fitz-base.h"
2
3 /* Make this thread local storage if you wish. */
4
5 static void *stdmalloc(fz_memorycontext *mem, int n)
6 {
7 #if 0
8 void *p = malloc(n);
9 if (!p)
10 fprintf(stderr, "failed to malloc %d bytes\n", n);
11 return p;
12 #else
13 return malloc(n);
14 #endif
15 }
16
17 static void *stdrealloc(fz_memorycontext *mem, void *p, int n)
18 {
19 #if 0
20 void *np = realloc(p, n);
21 if (np == nil)
22 fprintf(stderr, "realloc failed %d nytes", n);
23 else if (np == p)
24 fprintf(stderr, "realloc kept %d\n", n);
25 else
26 fprintf(stderr, "realloc moved %d\n", n);
27 return np;
28 #else
29 return realloc(p, n);
30 #endif
31 }
32
33 static void stdfree(fz_memorycontext *mem, void *p)
34 {
35 free(p);
36 }
37
38 static fz_memorycontext defmem = { stdmalloc, stdrealloc, stdfree };
39 static fz_memorycontext *curmem = &defmem;
40
41 fz_error fz_koutofmem = {
42 -1,
43 {"out of memory"},
44 {"<malloc>"},
45 {"memory.c"},
46 0
47 };
48
49 fz_memorycontext *
50 fz_currentmemorycontext()
51 {
52 return curmem;
53 }
54
55 void
56 fz_setmemorycontext(fz_memorycontext *mem)
57 {
58 curmem = mem;
59 }
60
61 void *
62 fz_malloc(int n)
63 {
64 fz_memorycontext *mem = fz_currentmemorycontext();
65 return mem->malloc(mem, n);
66 }
67
68 void *
69 fz_realloc(void *p, int n)
70 {
71 fz_memorycontext *mem = fz_currentmemorycontext();
72 return mem->realloc(mem, p, n);
73 }
74
75 void
76 fz_free(void *p)
77 {
78 fz_memorycontext *mem = fz_currentmemorycontext();
79 mem->free(mem, p);
80 }
81
82 char *
83 fz_strdup(char *s)
84 {
85 int len = strlen(s);
86 char *ns = fz_malloc(len + 1);
87 if (ns)
88 strcpy(ns, s);
89 return ns;
90 }
91