X-Git-Url: http://git.archive.openwrt.org/?p=project%2Flibubox.git;a=blobdiff_plain;f=list.h;h=8e61e473382a2de62d9d377c637613ba8e4e5c07;hp=8425aff9da71e1efff2eac72642937fcbd6a03a2;hb=ace64897d47b9bc7af277d8a3f8a0ff67976cba8;hpb=92da3a9bcc4934c04766e6e60aff254c04e92e97 diff --git a/list.h b/list.h index 8425aff..8e61e47 100644 --- a/list.h +++ b/list.h @@ -35,8 +35,11 @@ #define prefetch(x) #ifndef container_of -#define container_of(ptr, type, member) ( \ - (type *)( (char *)ptr - offsetof(type,member) )) +#define container_of(ptr, type, member) \ + ({ \ + const __typeof__(((type *) NULL)->member) *__mptr = (ptr); \ + (type *) ((char *) __mptr - offsetof(type, member)); \ + }) #endif struct list_head { @@ -45,6 +48,7 @@ struct list_head { }; #define LIST_HEAD_INIT(name) { &(name), &(name) } +#undef LIST_HEAD #define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name) static inline void @@ -116,17 +120,17 @@ list_del_init(struct list_head *entry) for (p = (head)->next, n = p->next; p != (head); p = n, n = p->next) #define list_for_each_entry(p, h, field) \ - for (p = list_first_entry(h, typeof(*p), field); &p->field != (h); \ - p = list_entry(p->field.next, typeof(*p), field)) + for (p = list_first_entry(h, __typeof__(*p), field); &p->field != (h); \ + p = list_entry(p->field.next, __typeof__(*p), field)) #define list_for_each_entry_safe(p, n, h, field) \ - for (p = list_first_entry(h, typeof(*p), field), \ - n = list_entry(p->field.next, typeof(*p), field); &p->field != (h);\ - p = n, n = list_entry(n->field.next, typeof(*n), field)) + for (p = list_first_entry(h, __typeof__(*p), field), \ + n = list_entry(p->field.next, __typeof__(*p), field); &p->field != (h);\ + p = n, n = list_entry(n->field.next, __typeof__(*n), field)) #define list_for_each_entry_reverse(p, h, field) \ - for (p = list_last_entry(h, typeof(*p), field); &p->field != (h); \ - p = list_entry(p->field.prev, typeof(*p), field)) + for (p = list_last_entry(h, __typeof__(*p), field); &p->field != (h); \ + p = list_entry(p->field.prev, __typeof__(*p), field)) #define list_for_each_prev(p, h) for (p = (h)->prev; p != (h); p = p->prev) #define list_for_each_prev_safe(p, n, h) for (p = (h)->prev, n = p->prev; p != (h); p = n, n = p->prev)