summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/dllist.c4
-rw-r--r--src/common/dllist.h12
2 files changed, 14 insertions, 2 deletions
diff --git a/src/common/dllist.c b/src/common/dllist.c
index 10f73e1..7e56bf4 100644
--- a/src/common/dllist.c
+++ b/src/common/dllist.c
@@ -45,11 +45,11 @@
void __dl_list_add(dl_list_item *new, dl_list_head *head, dl_list_item *prev, dl_list_item *next)
{
- if (prev != NULL) prev->next = new;
+ prev->next = new;
new->prev = prev;
new->next = next;
- if (next != NULL) next->prev = new;
+ next->prev = new;
if (*head == NULL)
*head = new;
diff --git a/src/common/dllist.h b/src/common/dllist.h
index 970edf9..670d3b9 100644
--- a/src/common/dllist.h
+++ b/src/common/dllist.h
@@ -44,6 +44,7 @@ typedef dl_list_item *dl_list_head;
#define DL_LIST_ITEM dl_list_item dummy
#define DLL_CAST(item) ((dl_list_item *)item)
+#define DLL_HCAST(item) ((dl_list_item **)item)
#define DL_LIST_HEAD_INIT(head) \
*(head) = NULL
@@ -87,6 +88,17 @@ unsigned int count_dl_list_items(dl_list_head);
#define dl_list_add_tail(new, head) \
__dl_list_add(DLL_CAST(new), (head), (dl_list_empty(*(head)) ? DLL_CAST(new) : (*(head))->prev), (dl_list_empty(*(head)) ? DLL_CAST(new) : *(head)))
+#define dl_list_insert_before(new, target, head) \
+ do \
+ { \
+ DLL_CAST(new)->prev = DLL_CAST(target)->prev; \
+ DLL_CAST(target)->prev->next = DLL_CAST(new); \
+ DLL_CAST(new)->next = DLL_CAST(target); \
+ DLL_CAST(target)->prev = DLL_CAST(new); \
+ if (DLL_CAST(target) == *head) *head = DLL_CAST(target); \
+ \
+ } while (0)
+
#define dl_list_del(item, head) \
do \
{ \