diff --git a/src/utils_llist.c b/src/utils_llist.c
index a81503578bc28b8e56da29d17dc72937788a6aa2..bf5f7e4944e335c6660eb0226cd8d43faa9aa2a8 100644 (file)
--- a/src/utils_llist.c
+++ b/src/utils_llist.c
* Florian Forster <octo at verplant.org>
*/
+#include "config.h"
+
#include <stdlib.h>
#include <string.h>
{
llentry_t *head;
llentry_t *tail;
+ int size;
};
/*
llentry_t *e_this;
llentry_t *e_next;
+ if (l == NULL)
+ return;
+
for (e_this = l->head; e_this != NULL; e_this = e_next)
{
e_next = e_this->next;
free (l);
}
-llentry_t *llentry_create (const char *key, void *value)
+llentry_t *llentry_create (char *key, void *value)
{
llentry_t *e;
e = (llentry_t *) malloc (sizeof (llentry_t));
- if (e == NULL)
- return (NULL);
-
- e->key = strdup (key);
- e->value = value;
- e->next = NULL;
-
- if (e->key == NULL)
+ if (e)
{
- free (e);
- return (NULL);
+ e->key = key;
+ e->value = value;
+ e->next = NULL;
}
return (e);
void llentry_destroy (llentry_t *e)
{
- free (e->key);
free (e);
}
l->tail->next = e;
l->tail = e;
+
+ ++(l->size);
}
void llist_prepend (llist_t *l, llentry_t *e)
{
e->next = l->head;
l->head = e;
+
+ if (l->tail == NULL)
+ l->tail = e;
+
+ ++(l->size);
}
void llist_remove (llist_t *l, llentry_t *e)
l->head = e->next;
if (l->tail == e)
l->tail = prev;
+
+ --(l->size);
+}
+
+int llist_size (llist_t *l)
+{
+ return (l ? l->size : 0);
}
llentry_t *llist_search (llist_t *l, const char *key)
{
llentry_t *e;
+ if (l == NULL)
+ return (NULL);
+
for (e = l->head; e != NULL; e = e->next)
if (strcmp (key, e->key) == 0)
break;
llentry_t *llist_head (llist_t *l)
{
+ if (l == NULL)
+ return (NULL);
return (l->head);
}
llentry_t *llist_tail (llist_t *l)
{
+ if (l == NULL)
+ return (NULL);
return (l->tail);
}