From 92e9b78371ebd9a005c4ce10aa1eb8c28638c2cd Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 9 Dec 2016 20:58:15 -0600 Subject: [PATCH] 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 --- libpkgconf/tuple.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libpkgconf/tuple.c b/libpkgconf/tuple.c index 6fbd0d6..2bcadc2 100644 --- a/libpkgconf/tuple.c +++ b/libpkgconf/tuple.c @@ -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);