GRASS Programmer's Manual
6.4.1(2011)
|
00001 00017 #include <stdlib.h> 00018 #include <grass/gis.h> 00019 #include <grass/glocale.h> 00020 00021 00034 void *G__malloc(const char *file, int line, size_t n) 00035 { 00036 void *buf; 00037 00038 if (n <= 0) 00039 n = 1; /* make sure we get a valid request */ 00040 00041 buf = malloc(n); 00042 if (!buf) 00043 G_fatal_error(_("G_malloc: unable to allocate %lu bytes at %s:%d"), 00044 (unsigned long) n, file, line); 00045 00046 return buf; 00047 } 00048 00065 void *G__calloc(const char *file, int line, size_t m, size_t n) 00066 { 00067 void *buf; 00068 00069 if (m <= 0) 00070 m = 1; /* make sure we get a valid requests */ 00071 if (n <= 0) 00072 n = 1; 00073 00074 buf = calloc(m, n); 00075 if (!buf) 00076 G_fatal_error(_("G_calloc: unable to allocate %lu * %lu bytes at %s:%d"), 00077 (unsigned long) m, (unsigned long) n, file, line); 00078 00079 return buf; 00080 } 00081 00082 00103 void *G__realloc(const char *file, int line, void *buf, size_t n) 00104 { 00105 if (n <= 0) 00106 n = 1; /* make sure we get a valid request */ 00107 00108 if (!buf) 00109 buf = malloc(n); 00110 else 00111 buf = realloc(buf, n); 00112 00113 if (!buf) 00114 G_fatal_error(_("G_realloc: unable to allocate %lu bytes at %s:%d"), 00115 (unsigned long) n, file, line); 00116 00117 return buf; 00118 } 00119 00120 00127 void G_free(void *buf) 00128 { 00129 free(buf); 00130 }