File: list.c

package info (click to toggle)
imapfilter 1%3A1.2.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 300 kB
  • ctags: 315
  • sloc: ansic: 3,392; sh: 182; makefile: 103
file content (59 lines) | stat: -rw-r--r-- 759 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>

#include "imapfilter.h"
#include "list.h"


/*
 * Add a new element at the end of the list.
 */
list *
list_append(list *lst, void *data)
{
	list *l, *nl;

	nl = (list *)xmalloc(sizeof(list));
	nl->data = data;
	nl->prev = nl->next = NULL;

	if (lst != NULL) {
		for (l = lst; l->next != NULL; l = l->next);
		l->next = nl;
		nl->prev = l;

		return lst;
	} else {
		return nl;
	}
}


/*
 * Remove an element from the list.
 */
list *
list_remove(list *lst, void *data)
{
	list *l;

	l = lst;
	while (l != NULL) {
		if (l->data != data)
			l = l->next;
		else {
			if (l->prev)
				l->prev->next = l->next;
			if (l->next)
				l->next->prev = l->prev;
			if (lst == l)
				lst = lst->next;

			xfree(l);

			break;
		}
	}

	return lst;
}