//移植linux内核(3.0.13)的链表实现进windows下,VS编译通过。
//待全面测试
//待增加hlist部分
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* transplant linux implement */
#define container_of(ptr, type, member) ((type *)( \
(PCHAR)(address) - \
(ULONG_PTR)(&((type *)0)->field)))
/* linux kernel list implementation */
typedef int le;
typedef struct list_head lh;
typedef struct hlist_node hn;
struct list_head{lh *next, *prev;};
struct hlist_head{hn *first;};
struct hlist_node{hn *prev, **pprev;};
#define LIST_HEAD_INIT(name) {&(name), &(name)}
#define LIST_HEAD(name) lh name = LIST_HEAD_INIT(name)
static inline void INIT_LIST_HEAD(lh *list)
{
list->next = list;
list->prev = list;
}
static inline void __list_add(lh *n, lh *prev, lh *next)
{
next->prev = n;
prev->next = n;
n->next = next;
n->prev = prev;
}
static inline void list_add(lh *n, lh *head)
{
__list_add(n, head, head->next);
}
static inline void list_add_tail(lh *n, lh *head)
{
__list_add(n, head->prev, head);
}
static inline void __list_del(lh *prev, lh *next)
{
next->prev = prev;
prev->next = next;
}
static inline void __list_del_entry(lh *entry)
{
__list_del(entry->prev, entry->next);
}
static inline void list_del(lh *entry)
{
__list_del_entry(entry);
}
static inline void list_replace(lh *n, lh *old)
{
n->next = old->next;
n->prev = old->prev;
n->next->prev =