[libc-commits] [libc] [libc] Provide sys/queue.h (PR #78081)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Wed Jan 17 08:59:37 PST 2024


================
@@ -96,27 +148,61 @@
     struct type *next;                                                         \
   }
 
+#define STAILQ_CLASS_ENTRY(type)                                               \
+  struct {                                                                     \
+    class type *next;                                                          \
+  }
+
 // Singly-linked tail queue access methods.
 
 #define STAILQ_EMPTY(head) ((head)->first == NULL)
 #define STAILQ_FIRST(head) ((head)->first)
+#define STAILQ_LAST(head, type, field)                                         \
+  STAILQ_EMPTY(head)                                                           \
+  ? NULL                                                                       \
+  : (QUEUE_TYPEOF(type) *)((char *)(head)->last -                              \
+                           offsetof(QUEUE_TYPEOF(type), field))
----------------
nickdesaulniers wrote:

as you define `offsetof`, providing a `containerof` for us would make this slightly less gross.

https://github.com/llvm/llvm-project/pull/78081


More information about the libc-commits mailing list