[apparmor] [patch 02/21] cleanup the list fns and use a little bit.
john.johansen at canonical.com
john.johansen at canonical.com
Mon Mar 17 23:29:12 UTC 2014
Yes its seems pointless because these will eventually get replaced by
stl. But until then
Signed-off-by: John Johansen <john.johansen at canonical.com>
---
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
@@ -107,17 +107,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
@@ -350,11 +350,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;
@@ -376,11 +372,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; \
More information about the AppArmor
mailing list