callbacks.c 971 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. @file callbacks.c
  3. @brief ENet callback functions
  4. */
  5. #define ENET_BUILDING_LIB 1
  6. #include "enet/enet.h"
  7. static ENetCallbacks callbacks = { malloc, free, abort };
  8. int
  9. enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits)
  10. {
  11. if (version < ENET_VERSION_CREATE (1, 3, 0))
  12. return -1;
  13. if (inits -> malloc != NULL || inits -> free != NULL)
  14. {
  15. if (inits -> malloc == NULL || inits -> free == NULL)
  16. return -1;
  17. callbacks.malloc = inits -> malloc;
  18. callbacks.free = inits -> free;
  19. }
  20. if (inits -> no_memory != NULL)
  21. callbacks.no_memory = inits -> no_memory;
  22. return enet_initialize ();
  23. }
  24. ENetVersion
  25. enet_linked_version (void)
  26. {
  27. return ENET_VERSION;
  28. }
  29. void *
  30. enet_malloc (size_t size)
  31. {
  32. void * memory = callbacks.malloc (size);
  33. if (memory == NULL)
  34. callbacks.no_memory ();
  35. return memory;
  36. }
  37. void
  38. enet_free (void * memory)
  39. {
  40. callbacks.free (memory);
  41. }