2 * Copyright (c) 2004-2005 Sergey Lyubka <valenok@gmail.com>
5 * "THE BEER-WARE LICENSE" (Revision 42):
6 * Sergey Lyubka wrote this file. As long as you retain this notice you
7 * can do whatever you want with this stuff. If we meet some day, and you think
8 * this stuff is worth it, you can buy me a beer in return.
11 #ifndef LLIST_HEADER_INCLUDED
12 #define LLIST_HEADER_INCLUDED
22 #define LL_INIT(N) ((N)->next = (N)->prev = (N))
24 #define LL_HEAD(H) struct llhead H = { &H, &H }
26 #define LL_ENTRY(P,T,N) ((T *)((char *)(P) - offsetof(T, N)))
28 #define LL_ADD(H, N) \
30 ((H)->next)->prev = (N); \
31 (N)->next = ((H)->next); \
36 #define LL_TAIL(H, N) \
38 ((H)->prev)->next = (N); \
39 (N)->prev = ((H)->prev); \
46 ((N)->next)->prev = ((N)->prev); \
47 ((N)->prev)->next = ((N)->next); \
51 #define LL_EMPTY(N) ((N)->next == (N))
53 #define LL_FOREACH(H,N) for (N = (H)->next; N != (H); N = (N)->next)
55 #define LL_FOREACH_SAFE(H,N,T) \
56 for (N = (H)->next, T = (N)->next; N != (H); \
57 N = (T), T = (N)->next)
59 #endif /* LLIST_HEADER_INCLUDED */