OSDN Git Service

libdrm: Implement drmParsePciDeviceInfo for FreeBSD
[android-x86/external-libdrm.git] / util_double_list.h
index 27e0761..7e48b26 100644 (file)
@@ -98,13 +98,19 @@ static inline void list_delinit(struct list_head *item)
 #define LIST_ENTRY(__type, __item, __field)   \
     ((__type *)(((char *)(__item)) - offsetof(__type, __field)))
 
+#define LIST_FIRST_ENTRY(__ptr, __type, __field)   \
+    LIST_ENTRY(__type, (__ptr)->next, __field)
+
+#define LIST_LAST_ENTRY(__ptr, __type, __field)   \
+    LIST_ENTRY(__type, (__ptr)->prev, __field)
+
 #define LIST_IS_EMPTY(__list)                   \
     ((__list)->next == (__list))
 
 #ifndef container_of
 #define container_of(ptr, sample, member)                              \
     (void *)((char *)(ptr)                                             \
-            - ((char *)&(sample)->member - (char *)(sample)))
+            - ((char *)&((typeof(sample))0)->member))
 #endif
 
 #define LIST_FOR_EACH_ENTRY(pos, head, member)                         \