-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvcode_os_funcs.c
More file actions
51 lines (41 loc) · 789 Bytes
/
convcode_os_funcs.c
File metadata and controls
51 lines (41 loc) · 789 Bytes
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
/*
* Copyright 2023 Corey Minyard
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* OS Functions for the convolutional coder.
*/
#include <stdlib.h>
#include <assert.h>
#include "convcode_os_funcs.h"
unsigned int mem_alloced;
static void *
o_zalloc(convcode_os_funcs *o, unsigned long size)
{
unsigned long *v;
assert(size);
v = calloc(size + sizeof(*v), 1);
if (v) {
*v = size;
v++;
mem_alloced += size;
o->bytes_allocated += size;
}
return v;
}
static void
o_free(convcode_os_funcs *o, void *to_free)
{
unsigned long *v = to_free;
assert(v);
v--;
assert(*v && *v <= mem_alloced);
mem_alloced -= *v;
free(v);
}
convcode_os_funcs osfuncs = {
.zalloc = o_zalloc,
.free = o_free,
};
convcode_os_funcs *o = &osfuncs;