#ifndef __WINE_SERVER_LIST_H
#define __WINE_SERVER_LIST_H
#include <stddef.h>
struct list
{
struct list *next;
struct list *prev;
};
/* add an element after the specified one */
static inline void list_add_after( struct list *elem, struct list *to_add )
{
to_add->next = elem->next;
to_add->prev = elem;
elem->next->prev = to_add;
elem->next = to_add;
}
/* add an element before the specified one */
static inline void list_add_before( struct list *elem, struct list *to_add )
{
to_add->next = elem;
to_add->prev = elem->prev;
elem->prev->next = to_add;
elem->prev = to_add;
}
/* add element at the head of the list */
static inline void list_add_head( struct list *list, struct list *elem )
{
list_add_after( list, elem );
}
/* add element at the tail of the list */
static inline void list_add_tail( struct list *list, struct list *elem )
{
list_add_before( list, elem );
}
/* remove an element from its list */
static inline void list_remove( struct list *elem )
{
elem->next->prev = elem->prev;
elem->prev->next = elem->next;
}
/* get the next element */
static inline struct list *list_next( const struct list *list, const struct list *elem )
{
struct list *ret = elem->next;
C语言实现的list -- 源码摘自wine
最新推荐文章于 2024-04-10 21:25:11 发布