PageRenderTime 27ms CodeModel.GetById 19ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/middleware/enet/callbacks.c

https://bitbucket.org/vivkin/gam3b00bs/
C | 47 lines | 32 code | 11 blank | 4 comment | 13 complexity | 2136ad825632f0d1330d5b2cb9b38769 MD5 | raw file
 1/** 
 2 @file callbacks.c
 3 @brief ENet callback functions
 4*/
 5#define ENET_BUILDING_LIB 1
 6#include "enet/enet.h"
 7
 8static ENetCallbacks callbacks = { malloc, free, abort };
 9
10int
11enet_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           
31void *
32enet_malloc (size_t size)
33{
34   void * memory = callbacks.malloc (size);
35
36   if (memory == NULL)
37     callbacks.no_memory ();
38
39   return memory;
40}
41
42void
43enet_free (void * memory)
44{
45   callbacks.free (memory);
46}
47