diff options
Diffstat (limited to 'apps/codecs/libgme/inflate/mallocer.c')
-rw-r--r-- | apps/codecs/libgme/inflate/mallocer.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/apps/codecs/libgme/inflate/mallocer.c b/apps/codecs/libgme/inflate/mallocer.c new file mode 100644 index 0000000000..41abedd09f --- /dev/null +++ b/apps/codecs/libgme/inflate/mallocer.c | |||
@@ -0,0 +1,86 @@ | |||
1 | |||
2 | /* | ||
3 | Based on the wiki viewer mallocer | ||
4 | Copyright (C) 2005 Dave Chapman | ||
5 | |||
6 | @ Modified to decompress memory buffer by gama | ||
7 | */ | ||
8 | |||
9 | #include "mallocer.h" | ||
10 | #include "codeclib.h" | ||
11 | |||
12 | unsigned char* mallocbuffer[MEMPOOL_MAX]; | ||
13 | long memory_ptr[MEMPOOL_MAX]; | ||
14 | size_t buffersize[MEMPOOL_MAX]; | ||
15 | |||
16 | int wpw_init_mempool(unsigned char mempool) | ||
17 | { | ||
18 | memory_ptr[mempool] = 0; | ||
19 | mallocbuffer[mempool] = (unsigned char *)ci->codec_get_buffer(&buffersize[mempool]); | ||
20 | // memset(mallocbuf[mempool], 0, bufsize[mempool]); | ||
21 | return 0; | ||
22 | } | ||
23 | |||
24 | int wpw_init_mempool_pdm(unsigned char mempool, | ||
25 | unsigned char* mem,long memsize) | ||
26 | { | ||
27 | memory_ptr[mempool] = 0; | ||
28 | mallocbuffer[mempool] = mem; | ||
29 | buffersize[mempool]=memsize; | ||
30 | return 0; | ||
31 | } | ||
32 | |||
33 | void wpw_reset_mempool(unsigned char mempool) | ||
34 | { | ||
35 | memory_ptr[mempool]=0; | ||
36 | } | ||
37 | |||
38 | void wpw_destroy_mempool(unsigned char mempool) | ||
39 | { | ||
40 | memory_ptr[mempool] = 0; | ||
41 | mallocbuffer[mempool] =0; | ||
42 | buffersize[mempool]=0; | ||
43 | } | ||
44 | |||
45 | long wpw_available(unsigned char mempool) | ||
46 | { | ||
47 | return buffersize[mempool]-memory_ptr[mempool]; | ||
48 | } | ||
49 | |||
50 | void* wpw_malloc(unsigned char mempool,size_t size) | ||
51 | { | ||
52 | void* x; | ||
53 | |||
54 | if (memory_ptr[mempool] + size > buffersize[mempool] ) | ||
55 | return NULL; | ||
56 | |||
57 | x=&mallocbuffer[mempool][memory_ptr[mempool]]; | ||
58 | memory_ptr[mempool]+=(size+3)&~3; /* Keep memory 32-bit aligned */ | ||
59 | |||
60 | return(x); | ||
61 | } | ||
62 | |||
63 | void* wpw_calloc(unsigned char mempool,size_t nmemb, size_t size) | ||
64 | { | ||
65 | void* x; | ||
66 | x = wpw_malloc(mempool,nmemb*size); | ||
67 | if (x == NULL) | ||
68 | return NULL; | ||
69 | |||
70 | memset(x,0,nmemb*size); | ||
71 | return(x); | ||
72 | } | ||
73 | |||
74 | void wpw_free(unsigned char mempool,void* ptr) | ||
75 | { | ||
76 | (void)ptr; | ||
77 | (void)mempool; | ||
78 | } | ||
79 | |||
80 | void* wpw_realloc(unsigned char mempool,void* ptr, size_t size) | ||
81 | { | ||
82 | void* x; | ||
83 | (void)ptr; | ||
84 | x = wpw_malloc(mempool,size); | ||
85 | return(x); | ||
86 | } | ||