comparison list.c @ 641:2b1bb792cd4d dropbear-tfm

- Update tfm changes to current default tip
author Matt Johnston <matt@ucc.asn.au>
date Mon, 21 Nov 2011 19:52:28 +0800
parents d204868e7943
children d68d61e7056a
comparison
equal deleted inserted replaced
640:76097ec1a29a 641:2b1bb792cd4d
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 }