callbacks.c 971 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. }