int catcierge_split(char *str, char delim, char ***array, size_t *length) { char *p; char **res; size_t count = 1; size_t k = 0; p = str; // Count occurance of delim in string while ((p = strchr(p, delim)) != NULL) { *p = 0; // Null terminate the deliminator. p++; // Skip past our new null count++; } // allocate dynamic array res = calloc( 1, count * sizeof(char *)); if (!res) return -1; p = str; for (k = 0; k < count; k++) { if (*p) { if (!(res[k] = strdup(p))) { catcierge_free_list(res, count); return -1; } } p = strchr(p, 0); // Look for next null p++; // Start of next string } *array = res; *length = count; return 0; }
void catcierge_free_rfid_allowed_list(catcierge_args_t *args) { catcierge_free_list(args->rfid_allowed, args->rfid_allowed_count); args->rfid_allowed_count = 0; }