 #ifndef __LIST_H
 #define __LIST_H

struct list_head {
        struct list_head *next, *prev;
};
typedef struct list_head st_list_head;


#define INIT_LIST_HEAD(ptr) do { \
        (ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)

/*
 * __list_add: insert new between prev and next.
 */
static inline void __list_add(struct list_head *new,
                              struct list_head *prev,
                              struct list_head *next)
{
        next->prev = new;
        new->next = next;
        new->prev = prev;
        prev->next = new;
}

/**
 * list_add: add a new entry to the end of the list.
 */
static inline void list_add1(struct list_head *new, struct list_head *head)
{
        __list_add(new, head->prev, head);
}

/*
 *__list_del: making the prev/next entries point to each other.
 */
static inline void __list_del(struct list_head *prev, struct list_head *next)
{
        next->prev = prev;
        prev->next = next;
}

/**
 * list_del: deletes entry from list.
 */
static inline void list_del(struct list_head *entry)
{
        __list_del(entry->prev, entry->next);
        entry->next = (void *) 0;
        entry->prev = (void *) 0;
}

/**
 * list_empty: check is list is empty.
 */
static inline int list_empty(struct list_head *head)
{
        return head->next == head;
}


/**
 * list_entry: retrieve the container struct.
 */
#define list_entry(ptr, type, member) \
        ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))

/**
 * list_for_each: traverse through the list.
 */
#define list_for_each(pos, head) \
        for (pos = (head)->next; pos != (head); \
                pos = pos->next)

/**
 * list_for_each_delete: traverse through the list with safe delete
 */
#define list_for_each_delete(pos, n, head) \
        for (pos = (head)->next, n = pos->next; pos != (head); \
                pos = n, n = pos->next)
#endif
