From 6a07dd2005735ca9114ae6d8d78ed031855ed733 Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Wed, 20 May 2020 17:33:26 -0400 Subject: [PATCH] context attributes: allow identical keys to over-write eachother Last one to be added wins. Signed-off-by: Robin Getz --- context.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/context.c b/context.c index 90140b71c..4d01fd9b1 100644 --- a/context.c +++ b/context.c @@ -414,6 +414,18 @@ int iio_context_add_attr(struct iio_context *ctx, const char *key, const char *value) { char **attrs, **values, *new_key, *new_val; + unsigned int i; + + for (i = 0; i < ctx->nb_attrs; i++) { + if(!strcmp(ctx->attrs[i], key)) { + new_val = iio_strdup(value); + if (!new_val) + return -ENOMEM; + free(ctx->values[i]); + ctx->values[i] = new_val; + return 0; + } + } attrs = realloc(ctx->attrs, (ctx->nb_attrs + 1) * sizeof(*ctx->attrs));