PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ strsplit()

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

Definition at line 200 of file raster2pgsql.c.

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

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

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function: