aboutsummaryrefslogtreecommitdiff
path: root/lib/list.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-03-21 14:06:35 -0700
committerBen Pfaff <blp@nicira.com>2011-03-21 14:09:32 -0700
commit0574c613cd00c03d287316a4c78c797ba0beea51 (patch)
tree0f051330f297db9e24e54a5ae95d0a84b7657f2e /lib/list.c
parent47ab7668cc7c57543a645b870855b0e763b1d0da (diff)
list: Allow list_front(), list_back() to take 'const' arguments.
It totally makes sense to pass a const struct list * to one of these functions. Ideally the return type would be the same as the argument type but C can't handle that, so this is the best second choice.
Diffstat (limited to 'lib/list.c')
-rw-r--r--lib/list.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/list.c b/lib/list.c
index 6d5f6fe0..0f4f2f84 100644
--- a/lib/list.c
+++ b/lib/list.c
@@ -127,20 +127,24 @@ list_pop_back(struct list *list)
return back;
}
-/* Returns the front element in 'list'.
- Undefined behavior if 'list' is empty. */
+/* Returns the front element in 'list_'.
+ Undefined behavior if 'list_' is empty. */
struct list *
-list_front(struct list *list)
+list_front(const struct list *list_)
{
+ struct list *list = (struct list *) list_;
+
assert(!list_is_empty(list));
return list->next;
}
-/* Returns the back element in 'list'.
- Undefined behavior if 'list' is empty. */
+/* Returns the back element in 'list_'.
+ Undefined behavior if 'list_' is empty. */
struct list *
-list_back(struct list *list)
+list_back(const struct list *list_)
{
+ struct list *list = (struct list *) list_;
+
assert(!list_is_empty(list));
return list->prev;
}