X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_llist.c;h=7fae025d62233ca51613268369239c43f516f973;hb=3469385f04ffcfa2f4ef06d34ed4b24acb378b34;hp=d5db9dc03abbab0d84df4676ec12a4dffea409e2;hpb=0b88f6888705e92ce4472435a464730cf2ce2d5a;p=collectd.git diff --git a/src/utils_llist.c b/src/utils_llist.c index d5db9dc0..7fae025d 100644 --- a/src/utils_llist.c +++ b/src/utils_llist.c @@ -35,6 +35,7 @@ struct llist_s { llentry_t *head; llentry_t *tail; + int size; }; /* @@ -67,22 +68,16 @@ void llist_destroy (llist_t *l) 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); @@ -90,7 +85,6 @@ llentry_t *llentry_create (const char *key, void *value) void llentry_destroy (llentry_t *e) { - free (e->key); free (e); } @@ -104,6 +98,8 @@ void llist_append (llist_t *l, llentry_t *e) l->tail->next = e; l->tail = e; + + ++(l->size); } void llist_prepend (llist_t *l, llentry_t *e) @@ -113,6 +109,8 @@ void llist_prepend (llist_t *l, llentry_t *e) if (l->tail == NULL) l->tail = e; + + ++(l->size); } void llist_remove (llist_t *l, llentry_t *e) @@ -129,6 +127,13 @@ 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)