移植linux内核(3.0.13)的链表实现进windows下,VS编译通过。

这篇博客介绍了如何将Linux内核3.0.13中的链表实现移植到Windows系统下,并在VS中成功编译。提供了完整的链表操作函数,包括初始化、添加、删除等,适用于C语言编程。
摘要由CSDN通过智能技术生成
//移植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 =
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值