cleanup the list fns and use a little bit. Yes its seems pointless
because these will eventually get replaced by stl. But until then

Signed-off-by: John Johansen <[email protected]>

---
 parser/dbus.c   |   11 -----------
 parser/mount.c  |   12 ++----------
 parser/parser.h |   34 ++++++++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 21 deletions(-)

--- 2.9-test.orig/parser/dbus.c
+++ 2.9-test/parser/dbus.c
@@ -106,17 +106,6 @@
        return 1;
 }
 
-static int list_len(struct value_list *v)
-{
-       int len = 0;
-       struct value_list *tmp;
-
-       list_for_each(v, tmp)
-               len++;
-
-       return len;
-}
-
 static void move_conditional_value(char **dst_ptr, struct cond_entry *cond_ent)
 {
        if (*dst_ptr)
--- 2.9-test.orig/parser/mount.c
+++ 2.9-test/parser/mount.c
@@ -349,11 +349,7 @@
                if (strcmp(entry->name, "fstype") == 0 ||
                    strcmp(entry->name, "vfstype") == 0) {
                        PDEBUG("  extracting fstype\n");
-                       if (prev)
-                               prev->next = tmp;
-                       if (entry == *conds)
-                               *conds = tmp;
-                       entry->next = NULL;
+                       list_remove_at(*conds, prev, entry);
                        list_append(entry->vals, list);
                        list = entry->vals;
                        entry->vals = NULL;
@@ -375,11 +371,7 @@
                if ((strcmp(entry->name, "options") == 0 ||
                     strcmp(entry->name, "option") == 0) &&
                    entry->eq == eq) {
-                       if (prev)
-                               prev->next = tmp;
-                       if (entry == *conds)
-                               *conds = tmp;
-                       entry->next = NULL;
+                       list_remove_at(*conds, prev, entry);
                        PDEBUG("  extracting option %s\n", entry->name);
                        list_append(entry->vals, list);
                        list = entry->vals;
--- 2.9-test.orig/parser/parser.h
+++ 2.9-test/parser/parser.h
@@ -212,6 +212,40 @@
                ___tmp->next = (LISTB);         \
        } while (0)
 
+#define list_len(LIST)         \
+({                             \
+       int len = 0;            \
+       typeof(LIST) tmp;               \
+       list_for_each((LIST), tmp)      \
+               len++;          \
+       len;                    \
+})
+
+#define list_find_prev(LIST, ENTRY)    \
+({                                     \
+       typeof(ENTRY) tmp, prev = NULL; \
+       list_for_each((LIST), tmp) {    \
+               if (tmp == (ENTRY))     \
+                       break;          \
+               prev = tmp;             \
+       }                               \
+       prev;                           \
+})
+
+#define list_remove_at(LIST, PREV, ENTRY)                      \
+       if (PREV)                                               \
+               (PREV)->next = (ENTRY)->next;                   \
+       if ((ENTRY) == (LIST))                                  \
+               (LIST) = (ENTRY)->next;                         \
+       (ENTRY)->next = NULL;                                   \
+
+#define list_remove(LIST, ENTRY)                               \
+do {                                                           \
+       typeof(ENTRY) prev = list_find_prev((LIST), (ENTRY));   \
+       list_remove_at((LIST), prev, (ENTRY));                  \
+} while (0)
+
+
 #define DUP_STRING(orig, new, field, fail_target) \
        do {                                                                    
\
                (new)->field = ((orig)->field) ? strdup((orig)->field) : NULL;  
\


-- 
AppArmor mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor

Reply via email to