Simplified distributed block storage with strong consistency, like in Ceph
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

52 lines
1001 B

  1. // Copyright (c) Vitaliy Filippov, 2019+
  2. // License: VNPL-1.0 or GNU GPL-2.0+ (see README.md for details)
  3. #pragma once
  4. #include <malloc.h>
  5. #include <stdlib.h>
  6. inline void* memalign_or_die(size_t alignment, size_t size)
  7. {
  8. void *buf = memalign(alignment, size);
  9. if (!buf)
  10. {
  11. printf("Failed to allocate %lu bytes\n", size);
  12. exit(1);
  13. }
  14. return buf;
  15. }
  16. inline void* malloc_or_die(size_t size)
  17. {
  18. void *buf = malloc(size);
  19. if (!buf)
  20. {
  21. printf("Failed to allocate %lu bytes\n", size);
  22. exit(1);
  23. }
  24. return buf;
  25. }
  26. inline void* realloc_or_die(void *ptr, size_t size)
  27. {
  28. void *buf = realloc(ptr, size);
  29. if (!buf)
  30. {
  31. printf("Failed to allocate %lu bytes\n", size);
  32. exit(1);
  33. }
  34. return buf;
  35. }
  36. inline void* calloc_or_die(size_t nmemb, size_t size)
  37. {
  38. void *buf = calloc(nmemb, size);
  39. if (!buf)
  40. {
  41. printf("Failed to allocate %lu bytes\n", size * nmemb);
  42. exit(1);
  43. }
  44. return buf;
  45. }