diff options
| author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-25 21:32:25 -0400 |
|---|---|---|
| committer | Nils Wallménius <nils@rockbox.org> | 2012-04-25 22:13:20 +0200 |
| commit | f40bfc9267b13b54e6379dfe7539447662879d24 (patch) | |
| tree | 9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libgme/inflate/mallocer.c | |
| parent | a0009907de7a0107d49040d8a180f140e2eff299 (diff) | |
| download | rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.bz2 rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.xz | |
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97
Reviewed-on: http://gerrit.rockbox.org/137
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libgme/inflate/mallocer.c')
| -rw-r--r-- | lib/rbcodec/codecs/libgme/inflate/mallocer.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libgme/inflate/mallocer.c b/lib/rbcodec/codecs/libgme/inflate/mallocer.c new file mode 100644 index 0000000..41abedd --- /dev/null +++ b/lib/rbcodec/codecs/libgme/inflate/mallocer.c @@ -0,0 +1,86 @@ + +/* + Based on the wiki viewer mallocer + Copyright (C) 2005 Dave Chapman + + @ Modified to decompress memory buffer by gama + */ + +#include "mallocer.h" +#include "codeclib.h" + +unsigned char* mallocbuffer[MEMPOOL_MAX]; +long memory_ptr[MEMPOOL_MAX]; +size_t buffersize[MEMPOOL_MAX]; + +int wpw_init_mempool(unsigned char mempool) +{ + memory_ptr[mempool] = 0; + mallocbuffer[mempool] = (unsigned char *)ci->codec_get_buffer(&buffersize[mempool]); + // memset(mallocbuf[mempool], 0, bufsize[mempool]); + return 0; +} + +int wpw_init_mempool_pdm(unsigned char mempool, + unsigned char* mem,long memsize) +{ + memory_ptr[mempool] = 0; + mallocbuffer[mempool] = mem; + buffersize[mempool]=memsize; + return 0; +} + +void wpw_reset_mempool(unsigned char mempool) +{ + memory_ptr[mempool]=0; +} + +void wpw_destroy_mempool(unsigned char mempool) +{ + memory_ptr[mempool] = 0; + mallocbuffer[mempool] =0; + buffersize[mempool]=0; +} + +long wpw_available(unsigned char mempool) +{ + return buffersize[mempool]-memory_ptr[mempool]; +} + +void* wpw_malloc(unsigned char mempool,size_t size) +{ + void* x; + + if (memory_ptr[mempool] + size > buffersize[mempool] ) + return NULL; + + x=&mallocbuffer[mempool][memory_ptr[mempool]]; + memory_ptr[mempool]+=(size+3)&~3; /* Keep memory 32-bit aligned */ + + return(x); +} + +void* wpw_calloc(unsigned char mempool,size_t nmemb, size_t size) +{ + void* x; + x = wpw_malloc(mempool,nmemb*size); + if (x == NULL) + return NULL; + + memset(x,0,nmemb*size); + return(x); +} + +void wpw_free(unsigned char mempool,void* ptr) +{ + (void)ptr; + (void)mempool; +} + +void* wpw_realloc(unsigned char mempool,void* ptr, size_t size) +{ + void* x; + (void)ptr; + x = wpw_malloc(mempool,size); + return(x); +} |