Mercurial > mplayer.hg
changeset 37067:b03e0fd957fd
Add listDup().
(Currently unused, but we will need it soon.)
author | ib |
---|---|
date | Thu, 24 Apr 2014 12:09:37 +0000 |
parents | 1843c6aaae4d |
children | 557b33c6a79a |
files | gui/util/list.c gui/util/list.h |
diffstat | 2 files changed, 31 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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);