#include <stdbool.h>
#include <stddef.h>
#include <assert.h>
+#include "c99_compat.h"
struct list_head
list->prev = item;
}
+static inline bool list_empty(struct list_head *list);
+
static inline void list_replace(struct list_head *from, struct list_head *to)
{
- to->prev = from->prev;
- to->next = from->next;
- from->next->prev = to;
- from->prev->next = to;
+ if (list_empty(from)) {
+ list_inithead(to);
+ } else {
+ to->prev = from->prev;
+ to->next = from->next;
+ from->next->prev = to;
+ from->prev->next = to;
+ }
}
static inline void list_del(struct list_head *item)
*/
static inline bool list_is_singular(const struct list_head *list)
{
- return list->next != NULL && list->next->next == list;
+ return list->next != NULL && list->next != list && list->next->next == list;
}
static inline unsigned list_length(struct list_head *list)