diff options
author | Jan Venekamp <jan@venekamp.net> | 2022-11-20 02:08:25 +0100 |
---|---|---|
committer | Hauke Mehrtens <hauke@hauke-m.de> | 2023-03-04 19:39:32 +0100 |
commit | b2f341769d1dcd3e670d2462ec6a0de2bb756fee (patch) | |
tree | abf8464497a1a994896901f7231a9f5851d87c5a | |
parent | 74f2797fca21fee456ca669e61dfde4e031c3db8 (diff) | |
download | uci-b2f341769d1dcd3e670d2462ec6a0de2bb756fee.tar.gz |
uci: maintain option position in uci_add_list
Maintain the position of an option in the list when a string option
is converted to a list option in uci_add_list.
Signed-off-by: Jan Venekamp <jan@venekamp.net>
-rw-r--r-- | list.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -115,7 +115,7 @@ uci_free_option(struct uci_option *o) } static struct uci_option * -uci_alloc_list(struct uci_section *s, const char *name) +uci_alloc_list(struct uci_section *s, const char *name, struct uci_list *after) { struct uci_package *p = s->package; struct uci_context *ctx = p->ctx; @@ -125,7 +125,7 @@ uci_alloc_list(struct uci_section *s, const char *name) o->type = UCI_TYPE_LIST; o->section = s; uci_list_init(&o->v.list); - uci_list_add(&s->options, &o->e.list); + uci_list_insert(after ? after : s->options.prev, &o->e.list); return o; } @@ -628,7 +628,7 @@ int uci_add_list(struct uci_context *ctx, struct uci_ptr *ptr) if (!ptr->o) { /* create new list */ UCI_TRAP_SAVE(ctx, error); - ptr->o = uci_alloc_list(ptr->s, ptr->option); + ptr->o = uci_alloc_list(ptr->s, ptr->option, NULL); UCI_TRAP_RESTORE(ctx); ptr->last = &ptr->o->e; } else if (ptr->o->type == UCI_TYPE_STRING) { @@ -636,7 +636,7 @@ int uci_add_list(struct uci_context *ctx, struct uci_ptr *ptr) struct uci_option *old = ptr->o; UCI_TRAP_SAVE(ctx, error); e2 = uci_alloc_generic(ctx, UCI_TYPE_ITEM, old->v.string, sizeof(struct uci_option)); - ptr->o = uci_alloc_list(ptr->s, ptr->option); + ptr->o = uci_alloc_list(ptr->s, ptr->option, &old->e.list); UCI_TRAP_RESTORE(ctx); uci_list_add(&ptr->o->v.list, &e2->list); |