libpkgconf: tuple: when calling pkgconf_tuple_add() on a collection that already has a tuple entry for 'key', replace it instead of adding a new entry

feature/tap-sh
William Pitcock 2016-12-09 20:58:15 -06:00
parent f7b7853932
commit 92e9b78371
1 changed files with 19 additions and 0 deletions

View File

@ -59,11 +59,30 @@ out:
free(workbuf);
}
static void
pkgconf_tuple_find_delete(pkgconf_list_t *list, const char *key)
{
pkgconf_node_t *node, *next;
PKGCONF_FOREACH_LIST_ENTRY_SAFE(list->head, next, node)
{
pkgconf_tuple_t *tuple = node->data;
if (!strcmp(tuple->key, key))
{
pkgconf_tuple_free_entry(tuple, list);
return;
}
}
}
pkgconf_tuple_t *
pkgconf_tuple_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *key, const char *value, bool parse)
{
pkgconf_tuple_t *tuple = calloc(sizeof(pkgconf_tuple_t), 1);
pkgconf_tuple_find_delete(list, key);
tuple->key = strdup(key);
if (parse)
tuple->value = pkgconf_tuple_parse(client, list, value);