comparison list.c @ 551:c3f2ec71e3d4 agent-client

New standard linked list to use, rather than adhoc SignKeyList or TCPFwdList
author Matt Johnston <matt@ucc.asn.au>
date Mon, 06 Jul 2009 12:59:13 +0000
parents
children d204868e7943
comparison
equal deleted inserted replaced
550:61c3513825b0 551:c3f2ec71e3d4
1 #include "options.h"
2 #include "dbutil.h"
3 #include "list.h"
4
5 void list_append(m_list *list, void *item) {
6 m_list_elem *elem;
7
8 elem = m_malloc(sizeof(*elem));
9 elem->item = item;
10 elem->list = list;
11 elem->next = NULL;
12 if (!list->first) {
13 list->first = elem;
14 elem->prev = NULL;
15 } else {
16 elem->prev = list->last;
17 list->last->next = elem;
18 }
19 list->last = elem;
20 }
21
22 m_list * list_new() {
23 m_list *ret = m_malloc(sizeof(m_list));
24 ret->first = ret->last = NULL;
25 return ret;
26 }
27
28 void * list_remove(m_list_elem *elem) {
29 void *item = elem->item;
30 m_list *list = elem->list;
31 if (list->first == elem)
32 {
33 list->first = elem->next;
34 }
35 if (list->last == elem)
36 {
37 list->last = elem->prev;
38 }
39 if (elem->prev)
40 {
41 elem->prev->next = elem->next;
42 }
43 if (elem->next)
44 {
45 elem->next->prev = elem->prev;
46 }
47 m_free(elem);
48 return item;
49 }