浏览代码

Added container_of(). This seems about the best place to put it, since

the definition of it uses offsetof(), and the two concepts are related.
tags/v0.9.3
Michael Brown 18 年前
父节点
当前提交
508dcdb303
共有 1 个文件被更改,包括 7 次插入2 次删除
  1. 7
    2
      src/include/stddef.h

+ 7
- 2
src/include/stddef.h 查看文件

@@ -2,12 +2,17 @@
2 2
 #define STDDEF_H
3 3
 
4 4
 /* for size_t */
5
-#include "stdint.h"
5
+#include <stdint.h>
6 6
 
7 7
 #undef NULL
8
-#define NULL	((void *)0)
8
+#define NULL ((void *)0)
9 9
 
10 10
 #undef offsetof
11 11
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
12 12
 
13
+#undef container_of
14
+#define container_of(ptr, type, member) ({                      \
15
+	const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
16
+	(type *)( (char *)__mptr - offsetof(type,member) );})
17
+
13 18
 #endif /* STDDEF_H */

正在加载...
取消
保存