Total Variation Deconvolution using Split Bregman
basic.c
Go to the documentation of this file.
1 
15 #include <stdlib.h>
16 #include <stdarg.h>
17 #include "basic.h"
18 
19 
21 void *MallocWithErrorMessage(size_t Size)
22 {
23  void *Ptr;
24 
25  if(!(Ptr = malloc(Size)))
26  ErrorMessage("Memory allocation of %u bytes failed.\n", Size);
27 
28  return Ptr;
29 }
30 
31 
33 void *ReallocWithErrorMessage(void *Ptr, size_t Size)
34 {
35  void *NewPtr;
36 
37  if(!(NewPtr = realloc(Ptr, Size)))
38  {
39  ErrorMessage("Memory reallocation of %u bytes failed.\n", Size);
40  Free(Ptr); /* Free the previous block on failure */
41  }
42 
43  return NewPtr;
44 }
45 
46 
48 void ErrorMessage(const char *Format, ...)
49 {
50  va_list Args;
51 
52  va_start(Args, Format);
53  /* Write a formatted error message to stderr */
54  vfprintf(stderr, Format, Args);
55  va_end(Args);
56 }