GRASS Programmer's Manual  6.4.3(2013)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
gis/alloc.c
Go to the documentation of this file.
1 
14 #include <stdlib.h>
15 #include <grass/gis.h>
16 #include <grass/glocale.h>
17 
30 void *G__malloc(const char *file, int line, size_t n)
31 {
32  void *buf;
33 
34  if (n <= 0)
35  n = 1; /* make sure we get a valid request */
36 
37  buf = malloc(n);
38  if (!buf) {
39  struct Cell_head window;
40 
41  G_get_window(&window);
42  G_important_message(_("Current region rows: %d, cols: %d"),
43  window.rows, window.cols);
44 
45  G_fatal_error(_("G_malloc: unable to allocate %lu bytes of memory at %s:%d"),
46  (unsigned long) n, file, line);
47  }
48 
49  return buf;
50 }
51 
68 void *G__calloc(const char *file, int line, size_t m, size_t n)
69 {
70  void *buf;
71 
72  if (m <= 0)
73  m = 1; /* make sure we get a valid requests */
74  if (n <= 0)
75  n = 1;
76 
77  buf = calloc(m, n);
78  if (!buf) {
79  struct Cell_head window;
80 
81  G_get_window(&window);
82  G_important_message(_("Current region rows: %d, cols: %d"),
83  window.rows, window.cols);
84 
85  G_fatal_error(_("G_calloc: unable to allocate %lu * %lu bytes of memory at %s:%d"),
86  (unsigned long) m, (unsigned long) n, file, line);
87  }
88 
89  return buf;
90 }
91 
92 
111 void *G__realloc(const char *file, int line, void *buf, size_t n)
112 {
113  if (n <= 0)
114  n = 1; /* make sure we get a valid request */
115 
116  if (!buf)
117  buf = malloc(n);
118  else
119  buf = realloc(buf, n);
120 
121  if (!buf) {
122  struct Cell_head window;
123 
124  G_get_window(&window);
125  G_important_message(_("Current region rows: %d, cols: %d"),
126  window.rows, window.cols);
127 
128  G_fatal_error(_("G_realloc: unable to allocate %lu bytes of memory at %s:%d"),
129  (unsigned long) n, file, line);
130  }
131 
132  return buf;
133 }
134 
135 
142 void G_free(void *buf)
143 {
144  free(buf);
145 }