New makefile solution: A single invocation of 'make' to build the entire tree. Fully...
[kugel-rb.git] / apps / codecs / libtremor / oggmalloc.c
blobca917ff3977dd6dde99833cb8cd168f59b21c219
1 #include "os_types.h"
3 static size_t tmp_ptr;
5 void ogg_malloc_init(void)
7 mallocbuf = ci->codec_get_buffer(&bufsize);
8 tmp_ptr = bufsize & ~3;
9 mem_ptr = 0;
12 void *ogg_malloc(size_t size)
14 void* x;
16 size = (size + 3) & ~3;
18 if (mem_ptr + size > tmp_ptr)
19 return NULL;
21 x = &mallocbuf[mem_ptr];
22 mem_ptr += size; /* Keep memory 32-bit aligned */
24 return x;
27 void *ogg_tmpmalloc(size_t size)
29 size = (size + 3) & ~3;
31 if (mem_ptr + size > tmp_ptr)
32 return NULL;
34 tmp_ptr -= size;
35 return &mallocbuf[tmp_ptr];
38 void *ogg_calloc(size_t nmemb, size_t size)
40 void *x;
41 x = ogg_malloc(nmemb * size);
42 if (x == NULL)
43 return NULL;
44 ci->memset(x, 0, nmemb * size);
45 return x;
48 void *ogg_tmpcalloc(size_t nmemb, size_t size)
50 void *x;
51 x = ogg_tmpmalloc(nmemb * size);
52 if (x == NULL)
53 return NULL;
54 ci->memset(x, 0, nmemb * size);
55 return x;
58 void *ogg_realloc(void *ptr, size_t size)
60 void *x;
61 (void)ptr;
62 x = ogg_malloc(size);
63 return x;
66 long ogg_tmpmalloc_pos(void)
68 return tmp_ptr;
71 void ogg_tmpmalloc_free(long pos)
73 tmp_ptr = pos;