This linked list implementation is partially based on kernel code. So it should be quite stable :)
Signed-off-by: Alexey Korolev alexey.korolev@endace.com --- src/util.h | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/src/util.h b/src/util.h index 70d3c4c..d1002a9 100644 --- a/src/util.h +++ b/src/util.h @@ -195,6 +195,38 @@ struct descloc_s { u32 addr; } PACKED;
+// Double linked lists with a single pointer list head +#define list_foreach_entry(head, entry) \ + for (entry = head; entry; entry = entry->next) + +#define list_foreach_entry_safe(head, next, entry) \ + for (entry = head; entry && ({next=entry->next; 1;}); \ + entry = next) + +#define list_del(entry) \ + do { \ + *(entry)->pprev = (entry)->next; \ + if ((entry)->next) \ + (entry)->next->pprev = (entry)->pprev; \ + } while (0) + +#define list_add_head(phead, entry) \ + do { \ + (entry)->next = *(phead); \ + if (*(phead)) \ + (*(phead))->pprev = &(entry)->next; \ + *(phead) = entry; \ + (entry)->pprev = phead; \ + } while (0) + +#define list_add_before(pos, entry) \ + do { \ + (entry)->pprev = (pos)->pprev; \ + (entry)->next = pos; \ + (pos)->pprev = &(entry)->next; \ + *(entry)->pprev = entry; \ + } while (0) + // util.c void cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx); struct bregs;