blob: ca917ff3977dd6dde99833cb8cd168f59b21c219 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include "os_types.h"
static size_t tmp_ptr;
void ogg_malloc_init(void)
{
mallocbuf = ci->codec_get_buffer(&bufsize);
tmp_ptr = bufsize & ~3;
mem_ptr = 0;
}
void *ogg_malloc(size_t size)
{
void* x;
size = (size + 3) & ~3;
if (mem_ptr + size > tmp_ptr)
return NULL;
x = &mallocbuf[mem_ptr];
mem_ptr += size; /* Keep memory 32-bit aligned */
return x;
}
void *ogg_tmpmalloc(size_t size)
{
size = (size + 3) & ~3;
if (mem_ptr + size > tmp_ptr)
return NULL;
tmp_ptr -= size;
return &mallocbuf[tmp_ptr];
}
void *ogg_calloc(size_t nmemb, size_t size)
{
void *x;
x = ogg_malloc(nmemb * size);
if (x == NULL)
return NULL;
ci->memset(x, 0, nmemb * size);
return x;
}
void *ogg_tmpcalloc(size_t nmemb, size_t size)
{
void *x;
x = ogg_tmpmalloc(nmemb * size);
if (x == NULL)
return NULL;
ci->memset(x, 0, nmemb * size);
return x;
}
void *ogg_realloc(void *ptr, size_t size)
{
void *x;
(void)ptr;
x = ogg_malloc(size);
return x;
}
long ogg_tmpmalloc_pos(void)
{
return tmp_ptr;
}
void ogg_tmpmalloc_free(long pos)
{
tmp_ptr = pos;
}
|