/*
- * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
#include <config.h>
#include "list.h"
-#include <assert.h>
/* Initializes 'list' as an empty list. */
void
void
list_splice(struct list *before, struct list *first, struct list *last)
{
- if (first == last)
+ if (first == last) {
return;
+ }
last = last->prev;
/* Cleanly remove 'first'...'last' from its current list. */
}
/* Adjusts pointers around 'list' to compensate for 'list' having been moved
- * around in memory (e.g. as a consequence of realloc()). */
+ * around in memory (e.g. as a consequence of realloc()).
+ *
+ * This always works if 'list' is a member of a list, or if 'list' is the head
+ * of a non-empty list. It fails badly, however, if 'list' is the head of an
+ * empty list; just use list_init() in that case. */
void
list_moved(struct list *list)
{
struct list *
list_front(const struct list *list_)
{
- struct list *list = (struct list *) list_;
+ struct list *list = CONST_CAST(struct list *, list_);
- assert(!list_is_empty(list));
+ ovs_assert(!list_is_empty(list));
return list->next;
}
struct list *
list_back(const struct list *list_)
{
- struct list *list = (struct list *) list_;
+ struct list *list = CONST_CAST(struct list *, list_);
- assert(!list_is_empty(list));
+ ovs_assert(!list_is_empty(list));
return list->prev;
}
const struct list *e;
size_t cnt = 0;
- for (e = list->next; e != list; e = e->next)
+ for (e = list->next; e != list; e = e->next) {
cnt++;
+ }
return cnt;
}