From aa041b415e0254a45cc54d161d6f242169d71c18 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 30 Dec 2016 10:44:01 -0600 Subject: [PATCH] libpkgconf: path: add naive path list filtering function --- doc/libpkgconf-path.rst | 2 +- libpkgconf/path.c | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/doc/libpkgconf-path.rst b/doc/libpkgconf-path.rst index 658f890..5017305 100644 --- a/doc/libpkgconf-path.rst +++ b/doc/libpkgconf-path.rst @@ -8,7 +8,7 @@ variables. .. c:function:: void pkgconf_path_add(const char *text, pkgconf_list_t *dirlist) - Adds a path node to a path list. + Adds a path node to a path list. If the path is already in the list, do nothing. :param char* text: The path text to add as a path node. :param pkgconf_list_t* dirlist: The path list to add the path node to. diff --git a/libpkgconf/path.c b/libpkgconf/path.c index 320e20c..b25407c 100644 --- a/libpkgconf/path.c +++ b/libpkgconf/path.c @@ -14,6 +14,23 @@ */ #include +#include + +static bool +path_list_contains_entry(const char *text, pkgconf_list_t *dirlist) +{ + pkgconf_node_t *n; + + PKGCONF_FOREACH_LIST_ENTRY(dirlist->head, n) + { + pkgconf_path_t *pn = n->data; + + if (!strcmp(text, pn->path)) + return true; + } + + return false; +} /* * !doc @@ -31,7 +48,7 @@ * * .. c:function:: void pkgconf_path_add(const char *text, pkgconf_list_t *dirlist) * - * Adds a path node to a path list. + * Adds a path node to a path list. If the path is already in the list, do nothing. * * :param char* text: The path text to add as a path node. * :param pkgconf_list_t* dirlist: The path list to add the path node to. @@ -42,6 +59,9 @@ pkgconf_path_add(const char *text, pkgconf_list_t *dirlist) { pkgconf_path_t *node; + if (path_list_contains_entry(text, dirlist)) + return; + node = calloc(sizeof(pkgconf_path_t), 1); node->path = strdup(text);