diff options
author | Matt Johnston <matt@ucc.asn.au> | 2010-02-27 11:53:18 +0000 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2010-02-27 11:53:18 +0000 |
commit | ddbfdb079991e9705c8874ae2d2dbd64394f269c (patch) | |
tree | 6358929d48902659b423493edf17831541c732ac /list.c | |
parent | 85288d7b6174b78af903fb55593bccd0014e5f30 (diff) | |
parent | 3b078445482f42dabfe4922e67a958dc607b166f (diff) |
merge of '48fdaa8706d1acda35e9d564adc9a1fbc96c18c8'
and '658fd03abd21e0da7c4c89b9fff9dc693c72daae'
--HG--
extra : convert_revision : 8064882fcaa13d586651021462b9014b74332107
Diffstat (limited to 'list.c')
-rw-r--r-- | list.c | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -0,0 +1,49 @@ +#include "options.h" +#include "dbutil.h" +#include "list.h" + +void list_append(m_list *list, void *item) { + m_list_elem *elem; + + elem = m_malloc(sizeof(*elem)); + elem->item = item; + elem->list = list; + elem->next = NULL; + if (!list->first) { + list->first = elem; + elem->prev = NULL; + } else { + elem->prev = list->last; + list->last->next = elem; + } + list->last = elem; +} + +m_list * list_new() { + m_list *ret = m_malloc(sizeof(m_list)); + ret->first = ret->last = NULL; + return ret; +} + +void * list_remove(m_list_elem *elem) { + void *item = elem->item; + m_list *list = elem->list; + if (list->first == elem) + { + list->first = elem->next; + } + if (list->last == elem) + { + list->last = elem->prev; + } + if (elem->prev) + { + elem->prev->next = elem->next; + } + if (elem->next) + { + elem->next->prev = elem->prev; + } + m_free(elem); + return item; +}
\ No newline at end of file |