more cleanup/list fixes
authorFelix Fietkau <nbd@openwrt.org>
Sat, 19 Jan 2008 22:21:44 +0000 (23:21 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 19 Jan 2008 22:21:44 +0000 (23:21 +0100)
libuci.h
list.c

index 50c20f1..de96f45 100644 (file)
--- a/libuci.h
+++ b/libuci.h
@@ -127,12 +127,13 @@ struct uci_option
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 #endif
 
-#define uci_list_entry(type, ptr) \
-       ((struct uci_#type *) ((char *)(ptr) - offsetof(struct uci_#type,list)))
-
-#define uci_foreach_entry(type, list, ptr)             \
-       for(ptr = uci_list_entry(type, (list)->next);   \
-               &ptr->list != list;                     \
-               ptr = uci_list_entry(type, ptr->list.next))
+#define uci_list_empty(list) (list->next == ptr)
+#define uci_list_entry(_type, _ptr) \
+       ((struct uci_ ## _type *) ((char *)(_ptr) - offsetof(struct uci_ ## _type,list)))
+
+#define uci_foreach_entry(_type, _list, _ptr)          \
+       for(_ptr = uci_list_entry(_type, (_list)->next);        \
+               &_ptr->list != (_list);                 \
+               _ptr = uci_list_entry(_type, _ptr->list.next))
 
 #endif
diff --git a/list.c b/list.c
index 51fca61..dee6a14 100644 (file)
--- a/list.c
+++ b/list.c
@@ -50,6 +50,7 @@ static void uci_drop_section(struct uci_section *section)
 {
        if (!section)
                return;
+       /* TODO: drop options */
        if (section->name)
                free(section->name);
        if (section->type)
@@ -83,9 +84,13 @@ error:
 
 static void uci_drop_file(struct uci_config *cfg)
 {
-       /* TODO: free children */
+       struct uci_section *s;
+
        if(!cfg)
                return;
+       uci_foreach_entry(section, &cfg->sections, s) {
+               uci_drop_section(s);
+       }
        if (cfg->name)
                free(cfg->name);
        free(cfg);