diff --git a/jni/su b/jni/su index 1bbf96a0a..9dab3bc8a 160000 --- a/jni/su +++ b/jni/su @@ -1 +1 @@ -Subproject commit 1bbf96a0a7a942798df58883a376b8024d0fae7f +Subproject commit 9dab3bc8ab28792993711f0a2450f9332b172687 diff --git a/jni/utils/list.c b/jni/utils/list.c index d7f5768c2..1181024e4 100644 --- a/jni/utils/list.c +++ b/jni/utils/list.c @@ -24,15 +24,19 @@ void list_insert_end(struct list_head *head, struct list_head *node) { list_insert(head->prev, node); } -void list_pop(struct list_head *pos) { +struct list_head *list_pop(struct list_head *pos) { + struct list_head *ret; + ret = pos->prev; // Maintain the list pos->prev->next = pos->next; pos->next->prev = pos->prev; // Remove references pos->next = pos; pos->prev = pos; + // Return the previous node in the list + return ret; } -void list_pop_end(struct list_head *head) { +struct list_head *list_pop_end(struct list_head *head) { return list_pop(head->prev); } diff --git a/jni/utils/list.h b/jni/utils/list.h index 9108f5d70..3fe1aca12 100644 --- a/jni/utils/list.h +++ b/jni/utils/list.h @@ -14,17 +14,30 @@ struct list_head { void init_list_head(struct list_head *head); void list_insert(struct list_head *pos, struct list_head *node); void list_insert_end(struct list_head *head, struct list_head *node); -void list_pop(struct list_head *pos); -void list_pop_end(struct list_head *head); +struct list_head *list_pop(struct list_head *pos); +struct list_head *list_pop_end(struct list_head *head); -#define list_entry(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ +#define list_entry(pos, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (pos); \ (type *)( (char *)__mptr - offsetof(type,member) );}) -#define list_for_each(pos, head) \ - for (pos = (head)->next; pos != (head); pos = pos->next) +#define list_for_each(ptr, head, type, member) \ + ptr = list_entry((head)->next, type, member); \ + for (struct list_head *__ = (head)->next; __ != (head); __ = __->next, ptr = list_entry(__, type, member)) -#define list_for_each_r(pos, head) \ - for (pos = (head)->prev; pos != (head); pos = pos->prev) +#define list_for_each_r(ptr, head, type, member) \ + ptr = list_entry((head)->prev, type, member); \ + for (struct list_head *__ = (head)->prev; __ != (head); __ = __->prev, ptr = list_entry(__, type, member)) -#endif \ No newline at end of file +#define list_destory(head, type, member, func) ({ \ + struct list_head *node = head->next; \ + while(node != head) { \ + node = node->next; \ + if (func) func(list_entry(node->prev, line_list, pos)); \ + free(list_entry(node->prev, line_list, pos)); \ + } \ + head->next = head; \ + head->prev = head; \ +}) + +#endif