1#include <stdio.h>
2#include <stdlib.h>
3
4#include "list.h"
5
6int cur_conn = 0;
7
8void bftpd_list_add(struct bftpd_list_element **list, void *data)
9{
10	struct bftpd_list_element *new = malloc(sizeof(struct bftpd_list_element));
11	struct bftpd_list_element *tmp = *list;
12	new->data = data;
13	new->next = NULL;
14	if (tmp) {
15		while (tmp->next)
16			tmp = tmp->next;
17		tmp->next = new;
18	} else
19		*list = new;
20	cur_conn++;
21}
22
23void bftpd_list_del(struct bftpd_list_element **list, int index)
24{
25	struct bftpd_list_element *tmp = *list;
26	struct bftpd_list_element *tmp2;
27	int i;
28	if (!index) {
29		tmp = tmp->next;
30		free(*list);
31		*list = tmp;
32	} else {
33		for (i = 0; i < index - 1; i++) {
34			if (!(tmp->next))
35				return;
36			tmp = tmp->next;
37		}
38		tmp2 = tmp->next;
39		tmp->next = tmp->next->next;
40		free(tmp2);
41	}
42	cur_conn--;
43}
44
45int bftpd_list_count(struct bftpd_list_element *list)
46{
47	int i = 1;
48	struct bftpd_list_element *tmp = list;
49	if (!tmp)
50		return 0;
51	while ((tmp = tmp->next))
52		i++;
53	return i;
54}
55
56void *bftpd_list_get(struct bftpd_list_element *list, int index)
57{
58	struct bftpd_list_element *tmp = list;
59	int i;
60	for (i = 0; i < index; i++) {
61		if (!(tmp->next))
62			return NULL;
63		tmp = tmp->next;
64	}
65	return tmp->data;
66}
67