GenSVM
gensvm_memory.c
Go to the documentation of this file.
1 
27 #include "gensvm_globals.h" // imports gensvm_memory.h
28 
48 void *mycalloc(const char *file, int line, unsigned long size,
49  size_t typesize)
50 {
51  void *ptr = calloc(size, typesize);
52 
53  if (!ptr) {
54  // LCOV_EXCL_START
55  fprintf(stderr, "[GenSVM Error]: Couldn't allocate memory: "
56  "%lu bytes (%s:%d)\n", size, file, line);
57  exit(EXIT_FAILURE);
58  // LCOV_EXCL_STOP
59  }
60  return ptr;
61 }
62 
81 void *mymalloc(const char *file, int line, unsigned long size)
82 {
83  void *ptr = malloc(size);
84  if (!ptr) {
85  // LCOV_EXCL_START
86  fprintf(stderr, "[GenSVM Error]: Couldn't allocate memory: "
87  "%lu bytes (%s:%d)\n", size, file, line);
88  exit(EXIT_FAILURE);
89  // LCOV_EXCL_STOP
90  }
91  return ptr;
92 }
93 
113 void *myrealloc(const char *file, int line, unsigned long size, void *var)
114 {
115  void *ptr = realloc(var, size);
116  if (!ptr) {
117  // LCOV_EXCL_START
118  fprintf(stderr, "[GenSVM Error]: Couldn't reallocate memory: "
119  "%lu bytes (%s:%d)\n", size, file, line);
120  exit(EXIT_FAILURE);
121  // LCOV_EXCL_STOP
122  }
123  return ptr;
124 }
Global definitions.
void * mymalloc(const char *file, int line, unsigned long size)
Wrapper for malloc() which warns when allocation fails.
Definition: gensvm_memory.c:81
void * myrealloc(const char *file, int line, unsigned long size, void *var)
Wrapper for realloc() which warns when allocation fails.
void * mycalloc(const char *file, int line, unsigned long size, size_t typesize)
Wrapper for calloc() which warns when allocation fails.
Definition: gensvm_memory.c:48