]> git.ipfire.org Git - thirdparty/squid.git/blame - src/dlink.cc
Correct buffer calculation for snprintf
[thirdparty/squid.git] / src / dlink.cc
CommitLineData
e1f7507e
AJ
1/*
2 * $Id$
3 */
f5bffbd5 4#include "config.h"
e1f7507e
AJ
5#include "dlink.h"
6
7/* dlink are Mem-pooled */
8#include "MemPool.h"
9/* for xstrdup() */
10#include "util.h"
11
12
13dlink_list ClientActiveRequests;
14
15MemAllocator *dlink_node_pool = NULL;
16
17dlink_node *
18dlinkNodeNew()
19{
20 if (dlink_node_pool == NULL)
21 dlink_node_pool = memPoolCreate("Dlink list nodes", sizeof(dlink_node));
22
23 /* where should we call delete dlink_node_pool;dlink_node_pool = NULL; */
24 return (dlink_node *)dlink_node_pool->alloc();
25}
26
27/** The node needs to be unlinked FIRST */
28void
29dlinkNodeDelete(dlink_node * m)
30{
31 if (m == NULL)
32 return;
33
34 dlink_node_pool->free(m);
35}
36
37void
38dlinkAdd(void *data, dlink_node * m, dlink_list * list)
39{
40 m->data = data;
41 m->prev = NULL;
42 m->next = list->head;
43
44 if (list->head)
45 list->head->prev = m;
46
47 list->head = m;
48
49 if (list->tail == NULL)
50 list->tail = m;
51}
52
53void
54dlinkAddAfter(void *data, dlink_node * m, dlink_node * n, dlink_list * list)
55{
56 m->data = data;
57 m->prev = n;
58 m->next = n->next;
59
60 if (n->next)
61 n->next->prev = m;
62 else {
63 assert(list->tail == n);
64 list->tail = m;
65 }
66
67 n->next = m;
68}
69
70void
71dlinkAddTail(void *data, dlink_node * m, dlink_list * list)
72{
73 m->data = data;
74 m->next = NULL;
75 m->prev = list->tail;
76
77 if (list->tail)
78 list->tail->next = m;
79
80 list->tail = m;
81
82 if (list->head == NULL)
83 list->head = m;
84}
85
86void
87dlinkDelete(dlink_node * m, dlink_list * list)
88{
89 if (m->next)
90 m->next->prev = m->prev;
91
92 if (m->prev)
93 m->prev->next = m->next;
94
95 if (m == list->head)
96 list->head = m->next;
97
98 if (m == list->tail)
99 list->tail = m->prev;
100
101 m->next = m->prev = NULL;
102}