X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=list%2Flist.c;fp=list%2Flist.c;h=b72f8f67d87705c7af25af874ec08269c6080e41;hp=0000000000000000000000000000000000000000;hb=2040a0c4726800b60f0a1967989c0004ca30d1d9;hpb=1e7eb5df1a634447ae57edf4c82a37f2d77e19ab diff --git a/list/list.c b/list/list.c new file mode 100644 index 00000000..b72f8f67 --- /dev/null +++ b/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; +}