]> git.ipfire.org Git - thirdparty/squid.git/blob - test-suite/test_tools.cc
CI: Upgrade GitHub Setup Node and CodeQL actions to Node 20 (#1845)
[thirdparty/squid.git] / test-suite / test_tools.cc
1 /*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 // XXX: This file is made of large pieces of src/tools.cc
10 // with only a few minor modifications. TODO: redesign or delete.
11
12 #include "squid.h"
13 #include "dlink.h"
14
15 void
16 dlinkAdd(void *data, dlink_node * m, dlink_list * list)
17 {
18 m->data = data;
19 m->prev = nullptr;
20 m->next = list->head;
21
22 if (list->head)
23 list->head->prev = m;
24
25 list->head = m;
26
27 if (list->tail == nullptr)
28 list->tail = m;
29 }
30
31 void
32 dlinkAddAfter(void *data, dlink_node * m, dlink_node * n, dlink_list * list)
33 {
34 m->data = data;
35 m->prev = n;
36 m->next = n->next;
37
38 if (n->next)
39 n->next->prev = m;
40 else {
41 assert(list->tail == n);
42 list->tail = m;
43 }
44
45 n->next = m;
46 }
47
48 void
49 dlinkAddTail(void *data, dlink_node * m, dlink_list * list)
50 {
51 m->data = data;
52 m->next = nullptr;
53 m->prev = list->tail;
54
55 if (list->tail)
56 list->tail->next = m;
57
58 list->tail = m;
59
60 if (list->head == nullptr)
61 list->head = m;
62 }
63
64 void
65 dlinkDelete(dlink_node * m, dlink_list * list)
66 {
67 if (m->next)
68 m->next->prev = m->prev;
69
70 if (m->prev)
71 m->prev->next = m->next;
72
73 if (m == list->head)
74 list->head = m->next;
75
76 if (m == list->tail)
77 list->tail = m->prev;
78
79 m->next = m->prev = nullptr;
80 }
81