list.c 634 B

123456789101112131415161718192021222324252627282930313233
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "list/list.h"
  4. struct list_head *list_check(struct list_head *h, const char *abortstr)
  5. {
  6. struct list_node *n, *p;
  7. int count = 0;
  8. if (h->n.next == &h->n) {
  9. if (h->n.prev != &h->n) {
  10. if (!abortstr)
  11. return NULL;
  12. fprintf(stderr, "%s: prev corrupt in empty %p\n",
  13. abortstr, h);
  14. abort();
  15. }
  16. return h;
  17. }
  18. for (p = &h->n, n = h->n.next; n != &h->n; p = n, n = n->next) {
  19. count++;
  20. if (n->prev != p) {
  21. if (!abortstr)
  22. return NULL;
  23. fprintf(stderr,
  24. "%s: prev corrupt in node %p (%u) of %p\n",
  25. abortstr, n, count, h);
  26. abort();
  27. }
  28. }
  29. return h;
  30. }