diff options
Diffstat (limited to 'util/list.h')
| -rw-r--r-- | util/list.h | 32 |
1 files changed, 3 insertions, 29 deletions
diff --git a/util/list.h b/util/list.h index d9531ea..73eb900 100644 --- a/util/list.h +++ b/util/list.h @@ -5,16 +5,13 @@ #define container_of(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type, member))) struct list_head { - struct list_head *prev; struct list_head *next; }; #define LIST_END NULL -#define LIST_EMPTY(list) do { \ - (list)->next = LIST_END; \ - (list)->prev = LIST_END; \ - } while(0); +#define LIST_EMPTY(list) (list)->next = LIST_END +#define LIST_INIT_EMPTY() (struct list_head){.next = NULL} #define list_entry(ptr, type, member) \ container_of(ptr, type, member) @@ -35,44 +32,21 @@ struct list_head { pos && (__next = pos->next,1); \ pos = __next) -static inline int list_is_head(struct list_head *l) -{ - return l->prev == LIST_END; -} - static inline int list_is_tail(struct list_head *l) { return l->next == LIST_END; } -static inline struct list_head *list_get_head(struct list_head *l) -{ - while(!list_is_head(l)) l = l->prev; - return l; -} - static inline struct list_head *list_get_tail(struct list_head *l) { while(!list_is_tail(l)) l = l->next; return l; } -static inline struct list_head *list_add( - struct list_head *head, - struct list_head *new) -{ - if(head) { - // new->next = head->next; - head->next = new; - } - new->prev = head; - return new; -} - static inline size_t list_len(struct list_head *head) { size_t n = 0; - list_for_each(pos, list_get_head(head)) n++; + list_for_each(pos, head) n++; return n; } |
