# HG changeset patch # User ib # Date 1398341377 0 # Node ID b03e0fd957fd5ae777e76e02af993d0d70afc8fb # Parent 1843c6aaae4d81595f2d48b24ba249bb089fb2a5 Add listDup(). (Currently unused, but we will need it soon.) diff -r 1843c6aaae4d -r b03e0fd957fd gui/util/list.c --- a/gui/util/list.c Thu Apr 24 11:56:18 2014 +0000 +++ b/gui/util/list.c Thu Apr 24 12:09:37 2014 +0000 @@ -350,6 +350,36 @@ } /** + * @brief Duplicate a string list (by allocating new memory). + * + * @note The list must be NULL-terminated. + * + * @param list string list to be duplicated + * + * @return duplicated list + */ +char **listDup(const char *const *list) +{ + char **dup = NULL; + + if (list) { + int i = 0; + + while (list[i]) + i++; + + dup = calloc(i + 1, sizeof(char *)); + + if (dup) { + while (--i >= 0) + dup[i] = strdup(list[i]); + } + } + + return dup; +} + +/** * @brief Append or insert a file to the playlist. * * @param what file to be added diff -r 1843c6aaae4d -r b03e0fd957fd gui/util/list.h --- a/gui/util/list.h Thu Apr 24 11:56:18 2014 +0000 +++ b/gui/util/list.h Thu Apr 24 12:09:37 2014 +0000 @@ -54,6 +54,7 @@ /// @name String list operations //@{ +char **listDup(const char *const *list); void listFree(char ***list); void listRepl(char ***list, const char *search, const char *replace); void listSet(char ***list, const char *entry);