summaryrefslogtreecommitdiffhomepage
path: root/list.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2009-07-06 12:59:13 +0000
committerMatt Johnston <matt@ucc.asn.au>2009-07-06 12:59:13 +0000
commitc742137dc8c8dd2163a2353d3382fdf2cae44c24 (patch)
tree25f52a38fb21d20051e2e44faa40ab25f45a5cad /list.c
parent9dc9aff0164ba777ae9806e9608af09aaf1a786e (diff)
New standard linked list to use, rather than adhoc SignKeyList or TCPFwdList
--HG-- branch : agent-client extra : convert_revision : 5465e639cc3f5ee0c6c55f0de6e7b6d5a8769da3
Diffstat (limited to 'list.c')
-rw-r--r--list.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/list.c b/list.c
new file mode 100644
index 0000000..8be1a3a
--- /dev/null
+++ b/list.c
@@ -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