+void
+ucimap_free_item(struct ucimap_section_data *sd, void *item)
+{
+ struct uci_alloc_custom *ac;
+ struct uci_alloc *a;
+ void *ptr = *((void **) item);
+ int i;
+
+ if (!ptr)
+ return;
+
+ *((void **)item) = NULL;
+ for (i = 0, a = sd->allocmap; i < sd->allocmap_len; i++, a++) {
+ if (a->ptr != ptr)
+ continue;
+
+ if (i != sd->allocmap_len - 1)
+ a->ptr = sd->allocmap[sd->allocmap_len - 1].ptr;
+
+ sd->allocmap_len--;
+ return;
+ }
+
+ for (i = 0, ac = sd->alloc_custom; i < sd->alloc_custom_len; i++, ac++) {
+ if (ac->ptr != ptr)
+ continue;
+
+ if (i != sd->alloc_custom_len - 1)
+ memcpy(ac, &sd->alloc_custom[sd->alloc_custom_len - 1],
+ sizeof(struct uci_alloc_custom));
+
+ ac->om->free(ac->section, ac->om, ac->ptr);
+ sd->alloc_custom_len--;
+ return;
+ }
+}
+
+int
+ucimap_resize_list(struct ucimap_section_data *sd, struct ucimap_list **list, int items)
+{
+ struct ucimap_list *new;
+ struct uci_alloc *a;
+ int i, offset = 0;
+ int size = sizeof(struct ucimap_list) + items * sizeof(union ucimap_data);
+
+ if (!*list) {
+ new = calloc(1, size);
+
+ ucimap_add_alloc(sd, new);
+ goto set;
+ }
+
+ for (i = 0, a = sd->allocmap; i < sd->allocmap_len; i++, a++) {
+ if (a->ptr != *list)
+ continue;
+
+ goto realloc;
+ }
+ return -ENOENT;
+
+realloc:
+ if (items > (*list)->size)
+ offset = (items - (*list)->size) * sizeof(union ucimap_data);
+
+ a->ptr = realloc(a->ptr, size);
+ if (offset)
+ memset((char *) a->ptr + offset, 0, size - offset);
+ new = a->ptr;
+
+set:
+ new->size = items;
+ *list = new;
+ return 0;
+}
+