diff --git a/src/scconf/scconf.c b/src/scconf/scconf.c index 94ecf8fb..99bfd7d1 100644 --- a/src/scconf/scconf.c +++ b/src/scconf/scconf.c @@ -366,6 +366,30 @@ int scconf_list_strings_length(const scconf_list * list) return len; } +const char **scconf_list_toarray(const scconf_list * list) +{ + const scconf_list * lp = list; + const char **tp; + int len = 0; + + while (lp) { + len++; + lp = lp->next; + } + tp = (const char **)malloc(sizeof(char *) * (len + 1)); + if (!tp) + return tp; + lp = list; + len = 0; + while (lp) { + tp[len] = lp->data; + len++; + lp = lp->next; + } + tp[len] = NULL; + return tp; +} + char *scconf_list_strdup(const scconf_list * list, const char *filler) { char *buf = NULL; diff --git a/src/scconf/scconf.h b/src/scconf/scconf.h index ac98a496..561451e8 100644 --- a/src/scconf/scconf.h +++ b/src/scconf/scconf.h @@ -213,6 +213,13 @@ extern int scconf_list_strings_length(const scconf_list * list); */ extern char *scconf_list_strdup(const scconf_list * list, const char *filler); +/* Returns an allocated array of const char *pointers to + * list elements. + * Last pointer is NULL + * Array must be freed, but pointers to strings belong to scconf_list + */ +extern const char **scconf_list_toarray(const scconf_list * list); + #ifdef __cplusplus } #endif