diff --git a/src/utils/llist.c b/src/utils/llist.c
index e853001bc45bf7fd9a02f55961930105f89366cf..b606324e56f96b5510a48f10f7a27d4a30db57a0 100644 (file)
--- a/src/utils/llist.c
+++ b/src/utils/llist.c
#include <assert.h>
#include <stdlib.h>
+#include <strings.h>
#include <pthread.h>
sdb_llist_t *
sdb_llist_clone(sdb_llist_t *list)
{
- sdb_llist_t *clone;
+ sdb_llist_t *new;
sdb_llist_elem_t *elem;
if (! list)
return NULL;
- clone = sdb_llist_create();
- if (! clone)
+ new = sdb_llist_create();
+ if (! new)
return NULL;
if (! list->length) {
assert((! list->head) && (! list->tail));
- return clone;
+ return new;
}
for (elem = list->head; elem; elem = elem->next) {
- if (sdb_llist_append(clone, elem->obj)) {
- sdb_llist_destroy(clone);
+ if (sdb_llist_append(new, elem->obj)) {
+ sdb_llist_destroy(new);
return NULL;
}
}
- return clone;
+ return new;
} /* sdb_llist_clone */
void
} /* sdb_llist_append */
int
-sdb_llist_insert(sdb_llist_t *list, sdb_object_t *obj, size_t index)
+sdb_llist_insert(sdb_llist_t *list, sdb_object_t *obj, size_t idx)
{
sdb_llist_elem_t *prev;
sdb_llist_elem_t *next;
size_t i;
- if ((! list) || (! obj) || (index > list->length))
+ if ((! list) || (! obj) || (idx > list->length))
return -1;
pthread_rwlock_wrlock(&list->lock);
prev = NULL;
next = list->head;
- for (i = 0; i < index; ++i) {
+ for (i = 0; i < idx; ++i) {
prev = next;
next = next->next;
}
return NULL;
} /* sdb_llist_search */
+sdb_object_t *
+sdb_llist_search_by_name(sdb_llist_t *list, const char *key)
+{
+ sdb_llist_elem_t *elem;
+
+ if (! list)
+ return NULL;
+
+ pthread_rwlock_rdlock(&list->lock);
+
+ for (elem = list->head; elem; elem = elem->next)
+ if (! strcasecmp(elem->obj->name, key))
+ break;
+
+ pthread_rwlock_unlock(&list->lock);
+
+ if (elem)
+ return elem->obj;
+ return NULL;
+} /* sdb_llist_search_by_name */
+
sdb_object_t *
sdb_llist_shift(sdb_llist_t *list)
{