Browse Source

Add a DL_DELETE_INIT to delete items from a DL list and NULL the prev/next pointers

master
Con Kolivas 10 years ago
parent
commit
49266178e5
  1. 22
      src/utlist.h

22
src/utlist.h

@ -572,6 +572,28 @@ do {
} \ } \
} while (0) } 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) \ #define DL_COUNT(head,el,counter) \
DL_COUNT2(head,el,counter,next) \ DL_COUNT2(head,el,counter,next) \

Loading…
Cancel
Save