Skip to content

Commit

Permalink
context attributes: allow identical keys to over-write eachother
Browse files Browse the repository at this point in the history
Last one to be added wins.

Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz committed May 21, 2020
1 parent 956e384 commit 6a07dd2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 6a07dd2

Please sign in to comment.