]> git.ozlabs.org Git - ccan/blob - ccan/list/list.c
ccanlint clean and move endian.h to top of #includes (tests that it doesn't need...
[ccan] / ccan / list / list.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "list.h"
4
5 struct list_head *list_check(struct list_head *h, const char *abortstr)
6 {
7         struct list_node *n, *p;
8         int count = 0;
9
10         if (h->n.next == &h->n) {
11                 if (h->n.prev != &h->n) {
12                         if (!abortstr)
13                                 return NULL;
14                         fprintf(stderr, "%s: prev corrupt in empty %p\n",
15                                 abortstr, h);
16                         abort();
17                 }
18                 return h;
19         }
20
21         for (p = &h->n, n = h->n.next; n != &h->n; p = n, n = n->next) {
22                 count++;
23                 if (n->prev != p) {
24                         if (!abortstr)
25                                 return NULL;
26                         fprintf(stderr,
27                                 "%s: prev corrupt in node %p (%u) of %p\n",
28                                 abortstr, n, count, h);
29                         abort();
30                 }
31         }
32         return h;
33 }