diff options
author | Jim Meyering <jim@meyering.net> | 2007-08-07 09:06:05 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2007-08-07 09:06:05 +0000 |
commit | 08c9ff434bc9c2cd6bf69f577252affd42d8021a (patch) | |
tree | f7b8316b7017b880fee40fa7d9444e2c78783907 /lib/datastruct | |
parent | 41a94b54005c81b53501040bc4d886c9b0a3d763 (diff) | |
download | lvm2-08c9ff434bc9c2cd6bf69f577252affd42d8021a.tar.gz |
Add "const" attributes where possible: first cut.
Diffstat (limited to 'lib/datastruct')
-rw-r--r-- | lib/datastruct/btree.c | 13 | ||||
-rw-r--r-- | lib/datastruct/btree.h | 10 | ||||
-rw-r--r-- | lib/datastruct/list.c | 14 | ||||
-rw-r--r-- | lib/datastruct/list.h | 14 | ||||
-rw-r--r-- | lib/datastruct/str_list.c | 9 | ||||
-rw-r--r-- | lib/datastruct/str_list.h | 9 |
6 files changed, 36 insertions, 33 deletions
diff --git a/lib/datastruct/btree.c b/lib/datastruct/btree.c index 23b067be6..b99f667d1 100644 --- a/lib/datastruct/btree.c +++ b/lib/datastruct/btree.c @@ -55,7 +55,8 @@ static uint32_t _shuffle(uint32_t k) #endif } -static struct node **_lookup(struct node **c, uint32_t key, struct node **p) +static struct node **_lookup(struct node *const *c, uint32_t key, + struct node **p) { *p = NULL; while (*c) { @@ -70,10 +71,10 @@ static struct node **_lookup(struct node **c, uint32_t key, struct node **p) c = &(*c)->r; } - return c; + return (struct node **)c; } -void *btree_lookup(struct btree *t, uint32_t k) +void *btree_lookup(const struct btree *t, uint32_t k) { uint32_t key = _shuffle(k); struct node *p, **c = _lookup(&t->root, key, &p); @@ -102,7 +103,7 @@ int btree_insert(struct btree *t, uint32_t k, void *data) return 1; } -void *btree_get_data(struct btree_iter *it) +void *btree_get_data(const struct btree_iter *it) { return ((struct node *) it)->data; } @@ -114,7 +115,7 @@ static struct node *_left(struct node *n) return n; } -struct btree_iter *btree_first(struct btree *t) +struct btree_iter *btree_first(const struct btree *t) { if (!t->root) return NULL; @@ -122,7 +123,7 @@ struct btree_iter *btree_first(struct btree *t) return (struct btree_iter *) _left(t->root); } -struct btree_iter *btree_next(struct btree_iter *it) +struct btree_iter *btree_next(const struct btree_iter *it) { struct node *n = (struct node *) it; uint32_t k = n->key; diff --git a/lib/datastruct/btree.h b/lib/datastruct/btree.h index 66dea80ea..f91ced82a 100644 --- a/lib/datastruct/btree.h +++ b/lib/datastruct/btree.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. + * Copyright (C) 2001-2004, 2007 Sistina Software, Inc. All rights reserved. * Copyright (C) 2004 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. @@ -20,13 +20,13 @@ struct btree; struct btree *btree_create(struct dm_pool *mem); -void *btree_lookup(struct btree *t, uint32_t k); +void *btree_lookup(const struct btree *t, uint32_t k); int btree_insert(struct btree *t, uint32_t k, void *data); struct btree_iter; -void *btree_get_data(struct btree_iter *it); +void *btree_get_data(const struct btree_iter *it); -struct btree_iter *btree_first(struct btree *t); -struct btree_iter *btree_next(struct btree_iter *it); +struct btree_iter *btree_first(const struct btree *t); +struct btree_iter *btree_next(const struct btree_iter *it); #endif diff --git a/lib/datastruct/list.c b/lib/datastruct/list.c index 17ee0e28e..3918cf520 100644 --- a/lib/datastruct/list.c +++ b/lib/datastruct/list.c @@ -68,7 +68,7 @@ void list_del(struct list *elem) /* * Is the list empty? */ -int list_empty(struct list *head) +int list_empty(const struct list *head) { return head->n == head; } @@ -76,7 +76,7 @@ int list_empty(struct list *head) /* * Is this the first element of the list? */ -int list_start(struct list *head, struct list *elem) +int list_start(const struct list *head, const struct list *elem) { return elem->p == head; } @@ -84,7 +84,7 @@ int list_start(struct list *head, struct list *elem) /* * Is this the last element of the list? */ -int list_end(struct list *head, struct list *elem) +int list_end(const struct list *head, const struct list *elem) { return elem->n == head; } @@ -92,7 +92,7 @@ int list_end(struct list *head, struct list *elem) /* * Return first element of the list or NULL if empty */ -struct list *list_first(struct list *head) +struct list *list_first(const struct list *head) { return (list_empty(head) ? NULL : head->n); } @@ -100,7 +100,7 @@ struct list *list_first(struct list *head) /* * Return last element of the list or NULL if empty */ -struct list *list_last(struct list *head) +struct list *list_last(const struct list *head) { return (list_empty(head) ? NULL : head->p); } @@ -108,7 +108,7 @@ struct list *list_last(struct list *head) /* * Return the previous element of the list, or NULL if we've reached the start. */ -struct list *list_prev(struct list *head, struct list *elem) +struct list *list_prev(const struct list *head, const struct list *elem) { return (list_start(head, elem) ? NULL : elem->p); } @@ -116,7 +116,7 @@ struct list *list_prev(struct list *head, struct list *elem) /* * Return the next element of the list, or NULL if we've reached the end. */ -struct list *list_next(struct list *head, struct list *elem) +struct list *list_next(const struct list *head, const struct list *elem) { return (list_end(head, elem) ? NULL : elem->n); } diff --git a/lib/datastruct/list.h b/lib/datastruct/list.h index 316c537aa..00d4d743e 100644 --- a/lib/datastruct/list.h +++ b/lib/datastruct/list.h @@ -57,37 +57,37 @@ void list_del(struct list *elem); /* * Is the list empty? */ -int list_empty(struct list *head); +int list_empty(const struct list *head); /* * Is this the first element of the list? */ -int list_start(struct list *head, struct list *elem); +int list_start(const struct list *head, const struct list *elem); /* * Is this the last element of the list? */ -int list_end(struct list *head, struct list *elem); +int list_end(const struct list *head, const struct list *elem); /* * Return first element of the list or NULL if empty */ -struct list *list_first(struct list *head); +struct list *list_first(const struct list *head); /* * Return last element of the list or NULL if empty */ -struct list *list_last(struct list *head); +struct list *list_last(const struct list *head); /* * Return the previous element of the list, or NULL if we've reached the start. */ -struct list *list_prev(struct list *head, struct list *elem); +struct list *list_prev(const struct list *head, const struct list *elem); /* * Return the next element of the list, or NULL if we've reached the end. */ -struct list *list_next(struct list *head, struct list *elem); +struct list *list_next(const struct list *head, const struct list *elem); /* * Given the address v of an instance of 'struct list' called 'head' diff --git a/lib/datastruct/str_list.c b/lib/datastruct/str_list.c index 94705dc42..68660d990 100644 --- a/lib/datastruct/str_list.c +++ b/lib/datastruct/str_list.c @@ -66,7 +66,8 @@ int str_list_del(struct list *sll, const char *str) return 1; } -int str_list_dup(struct dm_pool *mem, struct list *sllnew, struct list *sllold) +int str_list_dup(struct dm_pool *mem, struct list *sllnew, + const struct list *sllold) { struct str_list *sl; @@ -85,7 +86,7 @@ int str_list_dup(struct dm_pool *mem, struct list *sllnew, struct list *sllold) /* * Is item on list? */ -int str_list_match_item(struct list *sll, const char *str) +int str_list_match_item(const struct list *sll, const char *str) { struct str_list *sl; @@ -99,7 +100,7 @@ int str_list_match_item(struct list *sll, const char *str) /* * Is at least one item on both lists? */ -int str_list_match_list(struct list *sll, struct list *sll2) +int str_list_match_list(const struct list *sll, const struct list *sll2) { struct str_list *sl; @@ -113,7 +114,7 @@ int str_list_match_list(struct list *sll, struct list *sll2) /* * Do both lists contain the same set of items? */ -int str_list_lists_equal(struct list *sll, struct list *sll2) +int str_list_lists_equal(const struct list *sll, const struct list *sll2) { struct str_list *sl; diff --git a/lib/datastruct/str_list.h b/lib/datastruct/str_list.h index 329a1f652..46fb76d71 100644 --- a/lib/datastruct/str_list.h +++ b/lib/datastruct/str_list.h @@ -19,9 +19,10 @@ struct list *str_list_create(struct dm_pool *mem); int str_list_add(struct dm_pool *mem, struct list *sll, const char *str); int str_list_del(struct list *sll, const char *str); -int str_list_match_item(struct list *sll, const char *str); -int str_list_match_list(struct list *sll, struct list *sll2); -int str_list_lists_equal(struct list *sll, struct list *sll2); -int str_list_dup(struct dm_pool *mem, struct list *sllnew, struct list *sllold); +int str_list_match_item(const struct list *sll, const char *str); +int str_list_match_list(const struct list *sll, const struct list *sll2); +int str_list_lists_equal(const struct list *sll, const struct list *sll2); +int str_list_dup(struct dm_pool *mem, struct list *sllnew, + const struct list *sllold); #endif |