GRASS Programmer's Manual
6.4.2(2012)
|
00001 #include <string.h> 00002 #include <stdlib.h> 00003 #include <grass/dbmi.h> 00004 00011 char *db_store(const char *s) 00012 { 00013 char *a; 00014 00015 a = db_malloc(strlen(s) + 1); 00016 if (a) 00017 strcpy(a, s); 00018 return a; 00019 } 00020 00027 void *db_malloc(int n) 00028 { 00029 void *s; 00030 00031 if (n <= 0) 00032 n = 1; 00033 s = malloc((unsigned int)n); 00034 if (s == NULL) 00035 db_memory_error(); 00036 return s; 00037 } 00038 00045 void *db_calloc(int n, int m) 00046 { 00047 void *s; 00048 00049 if (n <= 0) 00050 n = 1; 00051 if (m <= 0) 00052 m = 1; 00053 s = calloc((unsigned int)n, (unsigned int)m); 00054 if (s == NULL) 00055 db_memory_error(); 00056 return s; 00057 } 00058 00065 void *db_realloc(void *s, int n) 00066 { 00067 if (n <= 0) 00068 n = 1; 00069 if (s == NULL) 00070 s = malloc((unsigned int)n); 00071 else 00072 s = realloc(s, (unsigned int)n); 00073 if (s == NULL) 00074 db_memory_error(); 00075 return s; 00076 } 00077 00084 void *db_free(void *s) 00085 { 00086 free(s); 00087 }