libpkgconf: path: add naive path list filtering function

feature/tap-sh
William Pitcock 2016-12-30 10:44:01 -06:00
parent 54c3ca86a2
commit aa041b415e
2 changed files with 22 additions and 2 deletions

View File

@ -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.

View File

@ -14,6 +14,23 @@
*/
#include <libpkgconf/libpkgconf.h>
#include <libpkgconf/config.h>
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);