From 49266178e5a28ba09ab3d3958f54bde425e82341 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 25 Jan 2015 00:16:18 +1100 Subject: [PATCH] Add a DL_DELETE_INIT to delete items from a DL list and NULL the prev/next pointers --- src/utlist.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/utlist.h b/src/utlist.h index 48a8c7d0..b4558aee 100644 --- a/src/utlist.h +++ b/src/utlist.h @@ -572,6 +572,28 @@ do { } \ } while (0) +#define DL_DELETE_INIT(head,del) \ + DL_DELETE3(head,del,prev,next) + +#define DL_DELETE3(head,del,prev,next) \ +do { \ + assert((del)->prev != NULL); \ + if ((del)->prev == (del)) { \ + (head)=NULL; \ + } else if ((del)==(head)) { \ + (del)->next->prev = (del)->prev; \ + (head) = (del)->next; \ + } else { \ + (del)->prev->next = (del)->next; \ + if ((del)->next) { \ + (del)->next->prev = (del)->prev; \ + } else { \ + (head)->prev = (del)->prev; \ + } \ + } \ + (del)->prev = (del)->next = NULL; \ +} while (0) + #define DL_COUNT(head,el,counter) \ DL_COUNT2(head,el,counter,next) \