PostGIS  2.1.10dev-r@@SVN_REVISION@@
static char** strsplit ( const char *  str,
const char *  delimiter,
int *  n 
)
static

Definition at line 198 of file raster2pgsql.c.

References _, rtalloc(), rtdealloc(), rterror(), and rtrealloc().

Referenced by main().

198  {
199  char *tmp = NULL;
200  char **rtn = NULL;
201  char *token = NULL;
202 
203  *n = 0;
204  if (!str)
205  return NULL;
206 
207  /* copy str to tmp as strtok will mangle the string */
208  tmp = rtalloc(sizeof(char) * (strlen(str) + 1));
209  if (NULL == tmp) {
210  rterror(_("strsplit: Not enough memory"));
211  return NULL;
212  }
213  strcpy(tmp, str);
214 
215  if (!strlen(tmp) || !delimiter || !strlen(delimiter)) {
216  *n = 1;
217  rtn = (char **) rtalloc(*n * sizeof(char *));
218  if (NULL == rtn) {
219  rterror(_("strsplit: Not enough memory"));
220  return NULL;
221  }
222  rtn[0] = (char *) rtalloc(sizeof(char) * (strlen(tmp) + 1));
223  if (NULL == rtn[0]) {
224  rterror(_("strsplit: Not enough memory"));
225  return NULL;
226  }
227  strcpy(rtn[0], tmp);
228  rtdealloc(tmp);
229  return rtn;
230  }
231 
232  token = strtok(tmp, delimiter);
233  while (token != NULL) {
234  if (*n < 1) {
235  rtn = (char **) rtalloc(sizeof(char *));
236  }
237  else {
238  rtn = (char **) rtrealloc(rtn, (*n + 1) * sizeof(char *));
239  }
240  if (NULL == rtn) {
241  rterror(_("strsplit: Not enough memory"));
242  return NULL;
243  }
244 
245  rtn[*n] = NULL;
246  rtn[*n] = (char *) rtalloc(sizeof(char) * (strlen(token) + 1));
247  if (NULL == rtn[*n]) {
248  rterror(_("strsplit: Not enough memory"));
249  return NULL;
250  }
251 
252  strcpy(rtn[*n], token);
253  *n = *n + 1;
254 
255  token = strtok(NULL, delimiter);
256  }
257 
258  rtdealloc(tmp);
259  return rtn;
260 }
void rtdealloc(void *mem)
Definition: rt_api.c:882
#define _(String)
Definition: shpcommon.h:23
void * rtalloc(size_t size)
Raster core memory management functions.
Definition: rt_api.c:867
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
void * rtrealloc(void *mem, size_t size)
Definition: rt_api.c:875

Here is the call graph for this function:

Here is the caller graph for this function: