Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/enet/callbacks.c
9896 views
1
/**
2
@file callbacks.c
3
@brief ENet callback functions
4
*/
5
#define ENET_BUILDING_LIB 1
6
#include "enet/enet.h"
7
8
static ENetCallbacks callbacks = { malloc, free, abort };
9
10
int
11
enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits)
12
{
13
if (version < ENET_VERSION_CREATE (1, 3, 0))
14
return -1;
15
16
if (inits -> malloc != NULL || inits -> free != NULL)
17
{
18
if (inits -> malloc == NULL || inits -> free == NULL)
19
return -1;
20
21
callbacks.malloc = inits -> malloc;
22
callbacks.free = inits -> free;
23
}
24
25
if (inits -> no_memory != NULL)
26
callbacks.no_memory = inits -> no_memory;
27
28
return enet_initialize ();
29
}
30
31
ENetVersion
32
enet_linked_version (void)
33
{
34
return ENET_VERSION;
35
}
36
37
void *
38
enet_malloc (size_t size)
39
{
40
void * memory = callbacks.malloc (size);
41
42
if (memory == NULL)
43
callbacks.no_memory ();
44
45
return memory;
46
}
47
48
void
49
enet_free (void * memory)
50
{
51
callbacks.free (memory);
52
}
53
54
55