Quellcode durchsuchen

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 vor 18 Jahren
Ursprung
Commit
508dcdb303
1 geänderte Dateien mit 7 neuen und 2 gelöschten Zeilen
  1. 7
    2
      src/include/stddef.h

+ 7
- 2
src/include/stddef.h Datei anzeigen

@@ -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 */

Laden…
Abbrechen
Speichern