X-Git-Url: https://git.ozlabs.org/?p=ponghero.git;a=blobdiff_plain;f=ccan%2Flist%2Flist.c;fp=ccan%2Flist%2Flist.c;h=b72f8f67d87705c7af25af874ec08269c6080e41;hp=0000000000000000000000000000000000000000;hb=3b07a088e47dffe99415cb01f42ea89c9185bdc5;hpb=4b884e9e3bff9f777f705d364627ce49ff4cedd6 diff --git a/ccan/list/list.c b/ccan/list/list.c new file mode 100644 index 0000000..b72f8f6 --- /dev/null +++ b/ccan/list/list.c @@ -0,0 +1,33 @@ +#include +#include +#include "list/list.h" + +struct list_head *list_check(struct list_head *h, const char *abortstr) +{ + struct list_node *n, *p; + int count = 0; + + if (h->n.next == &h->n) { + if (h->n.prev != &h->n) { + if (!abortstr) + return NULL; + fprintf(stderr, "%s: prev corrupt in empty %p\n", + abortstr, h); + abort(); + } + return h; + } + + for (p = &h->n, n = h->n.next; n != &h->n; p = n, n = n->next) { + count++; + if (n->prev != p) { + if (!abortstr) + return NULL; + fprintf(stderr, + "%s: prev corrupt in node %p (%u) of %p\n", + abortstr, n, count, h); + abort(); + } + } + return h; +}