PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ strsplit()

static char** strsplit ( const char *  str,
const char *  delimiter,
uint32_t *  n 
)
static

Definition at line 209 of file raster2pgsql.c.

209  {
210  char *tmp = NULL;
211  char **rtn = NULL;
212  char *token = NULL;
213 
214  *n = 0;
215  if (!str)
216  return NULL;
217 
218  /* copy str to tmp as strtok will mangle the string */
219  tmp = rtalloc(sizeof(char) * (strlen(str) + 1));
220  if (NULL == tmp) {
221  rterror(_("strsplit: Not enough memory"));
222  return NULL;
223  }
224  strcpy(tmp, str);
225 
226  if (!strlen(tmp) || !delimiter || !strlen(delimiter)) {
227  *n = 1;
228  rtn = (char **) rtalloc(*n * sizeof(char *));
229  if (NULL == rtn) {
230  rterror(_("strsplit: Not enough memory"));
231  return NULL;
232  }
233  rtn[0] = (char *) rtalloc(sizeof(char) * (strlen(tmp) + 1));
234  if (NULL == rtn[0]) {
235  rterror(_("strsplit: Not enough memory"));
236  return NULL;
237  }
238  strcpy(rtn[0], tmp);
239  rtdealloc(tmp);
240  return rtn;
241  }
242 
243  token = strtok(tmp, delimiter);
244  while (token != NULL) {
245  if (*n < 1) {
246  rtn = (char **) rtalloc(sizeof(char *));
247  }
248  else {
249  rtn = (char **) rtrealloc(rtn, (*n + 1) * sizeof(char *));
250  }
251  if (NULL == rtn) {
252  rterror(_("strsplit: Not enough memory"));
253  return NULL;
254  }
255 
256  rtn[*n] = NULL;
257  rtn[*n] = (char *) rtalloc(sizeof(char) * (strlen(token) + 1));
258  if (NULL == rtn[*n]) {
259  rterror(_("strsplit: Not enough memory"));
260  return NULL;
261  }
262 
263  strcpy(rtn[*n], token);
264  *n = *n + 1;
265 
266  token = strtok(NULL, delimiter);
267  }
268 
269  rtdealloc(tmp);
270  return rtn;
271 }
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:191
void * rtrealloc(void *mem, size_t size)
Definition: rt_context.c:199
void rtdealloc(void *mem)
Definition: rt_context.c:206
#define str(s)
Definition: raster2pgsql.c:34
#define _(String)
Definition: shpcommon.h:24

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

Here is the call graph for this function: