From 361f3ea9ee577c5a3e2fed687a0b417b257c31de Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 22 Feb 2012 14:59:32 +1030 Subject: lib/ccan: import failtest and required ccan modules for TDB2 unit tests. New modules: failtest, list, time, read_write_all and tlist. Signed-off-by: Rusty Russell --- lib/ccan/list/list.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lib/ccan/list/list.c (limited to 'lib/ccan/list/list.c') diff --git a/lib/ccan/list/list.c b/lib/ccan/list/list.c new file mode 100644 index 0000000000..29dc30ba19 --- /dev/null +++ b/lib/ccan/list/list.c @@ -0,0 +1,43 @@ +/* Licensed under LGPLv2.1+ - see LICENSE file for details */ +#include +#include +#include "list.h" + +static void *corrupt(const char *abortstr, + const struct list_node *head, + const struct list_node *node, + unsigned int count) +{ + if (abortstr) { + fprintf(stderr, + "%s: prev corrupt in node %p (%u) of %p\n", + abortstr, node, count, head); + abort(); + } + return NULL; +} + +struct list_node *list_check_node(const struct list_node *node, + const char *abortstr) +{ + const struct list_node *p, *n; + int count = 0; + + for (p = node, n = node->next; n != node; p = n, n = n->next) { + count++; + if (n->prev != p) + return corrupt(abortstr, node, n, count); + } + /* Check prev on head node. */ + if (node->prev != p) + return corrupt(abortstr, node, node, 0); + + return (struct list_node *)node; +} + +struct list_head *list_check(const struct list_head *h, const char *abortstr) +{ + if (!list_check_node(&h->n, abortstr)) + return NULL; + return (struct list_head *)h; +} -- cgit