Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include "headers.h"
  2.  
  3. /*********/
  4. void _log(char *func, char *fmt, ...)
  5. {
  6. if (func != NULL) { fprintf(stdout, "[%s]", func); };
  7.  
  8. if (func != NULL && fmt != NULL) { fprintf(stdout, " "); };
  9.  
  10. if (fmt != NULL)
  11. {
  12. va_list argp;
  13. va_start(argp, fmt);
  14. vfprintf(stdout, fmt, argp);
  15. va_end(argp);
  16. };
  17.  
  18. fprintf(stdout, "\n");
  19. }
  20.  
  21. /*********/
  22. void _error(char* func, char* fmt, ...)
  23. {
  24. fprintf(stdout, "[ERROR]\n");
  25.  
  26. _log(func, fmt);
  27.  
  28. exit(0);
  29. }
  30.  
  31. /**********/
  32. void *_calloc(size_t count, size_t size)
  33. {
  34. void *p = NULL;
  35.  
  36. p = calloc(count, size);
  37.  
  38. if (p == NULL) { _error(__func__, "Allocation failed"); };
  39.  
  40. return p;
  41. }
  42.  
  43. /**********/
  44. void *_malloc(size_t size)
  45. {
  46. void *p = NULL;
  47.  
  48. p = malloc(size);
  49.  
  50. if (p == NULL) { _error(__func__, "Allocation failed"); };
  51.  
  52. return p;
  53. }
  54.  
  55. /**********/
  56. void *_realloc(void* ptr, size_t size)
  57. {
  58. void* p = NULL;
  59.  
  60. p = realloc(ptr, size);
  61.  
  62. if (p == NULL) { _error(__func__, "Allocation failed"); };
  63.  
  64. return p;
  65. }
  66.  
  67. /**********/
  68. void _free(void *p)
  69. {
  70. if (p != NULL) { free(p); };
  71. }
  72.  
  73. /**********/
  74. int _compare_int(const void* elem1, const void* elem2)
  75. {
  76. int f = *((int*)elem1);
  77. int s = *((int*)elem2);
  78. if (f > s) return 1;
  79. if (f < s) return -1;
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement