summaryrefslogtreecommitdiff
path: root/libs/enet/callbacks.c
diff options
context:
space:
mode:
authorBernd Wachter <bwachter-tmw@lart.info>2010-08-13 19:14:33 +0300
committerBernd Wachter <bwachter-tmw@lart.info>2010-08-15 00:34:20 +0300
commit7950455d2370bfcdd1ed5472c9e5401b0fd8dbe8 (patch)
tree9867118f14595a22bf648b089337b6df7f1192bd /libs/enet/callbacks.c
parent07d6c28b6cbd83a73b0613bffe67be90a86d58ca (diff)
downloadmana-7950455d2370bfcdd1ed5472c9e5401b0fd8dbe8.tar.gz
mana-7950455d2370bfcdd1ed5472c9e5401b0fd8dbe8.tar.bz2
mana-7950455d2370bfcdd1ed5472c9e5401b0fd8dbe8.tar.xz
mana-7950455d2370bfcdd1ed5472c9e5401b0fd8dbe8.zip
Add enet files
Diffstat (limited to 'libs/enet/callbacks.c')
-rw-r--r--libs/enet/callbacks.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/libs/enet/callbacks.c b/libs/enet/callbacks.c
new file mode 100644
index 00000000..f9412825
--- /dev/null
+++ b/libs/enet/callbacks.c
@@ -0,0 +1,47 @@
+/**
+ @file callbacks.c
+ @brief ENet callback functions
+*/
+#define ENET_BUILDING_LIB 1
+#include "enet/enet.h"
+
+static ENetCallbacks callbacks = { malloc, free, abort };
+
+int
+enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits)
+{
+ if (version < ENET_VERSION_CREATE (1, 3, 0))
+ return -1;
+
+ if (inits -> malloc != NULL || inits -> free != NULL)
+ {
+ if (inits -> malloc == NULL || inits -> free == NULL)
+ return -1;
+
+ callbacks.malloc = inits -> malloc;
+ callbacks.free = inits -> free;
+ }
+
+ if (inits -> no_memory != NULL)
+ callbacks.no_memory = inits -> no_memory;
+
+ return enet_initialize ();
+}
+
+void *
+enet_malloc (size_t size)
+{
+ void * memory = callbacks.malloc (size);
+
+ if (memory == NULL)
+ callbacks.no_memory ();
+
+ return memory;
+}
+
+void
+enet_free (void * memory)
+{
+ callbacks.free (memory);
+}
+