bullet3/examples/ThirdPartyLibs/enet/callbacks.c

44 lines
808 B
C
Raw Normal View History

2015-05-05 19:51:38 +00:00
/**
@file callbacks.c
@brief ENet callback functions
*/
#define ENET_BUILDING_LIB 1
#include "enet/enet.h"
static ENetCallbacks callbacks = {malloc, free, abort};
2015-05-05 19:51:38 +00:00
int enet_initialize_with_callbacks(ENetVersion version, const ENetCallbacks* inits)
2015-05-05 19:51:38 +00:00
{
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();
2015-05-05 19:51:38 +00:00
}
void* enet_malloc(size_t size)
2015-05-05 19:51:38 +00:00
{
void* memory = callbacks.malloc(size);
2015-05-05 19:51:38 +00:00
if (memory == NULL)
callbacks.no_memory();
2015-05-05 19:51:38 +00:00
return memory;
2015-05-05 19:51:38 +00:00
}
void enet_free(void* memory)
2015-05-05 19:51:38 +00:00
{
callbacks.free(memory);
2015-05-05 19:51:38 +00:00
}