]> git.ozlabs.org Git - ponghero.git/blobdiff - ccan/list/list.c
Prepare for release: rename to ponghero and pull in ccan.
[ponghero.git] / ccan / list / list.c
diff --git a/ccan/list/list.c b/ccan/list/list.c
new file mode 100644 (file)
index 0000000..b72f8f6
--- /dev/null
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <stdlib.h>
+#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;
+}