HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / wmem / wmem_list.c
blobdf9f07ceee9cb78d3574900b4619e6e5ae48f3ce
1 /* wmem_list.c
2 * Wireshark Memory Manager Doubly-Linked List
3 * Copyright 2012, Evan Huus <eapache@gmail.com>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <string.h>
27 #include <glib.h>
29 #include "wmem_core.h"
30 #include "wmem_list.h"
32 struct _wmem_list_frame_t {
33 struct _wmem_list_frame_t *next, *prev;
34 void *data;
37 struct _wmem_list_t {
38 guint count;
39 wmem_list_frame_t *head, *tail;
40 wmem_allocator_t *allocator;
43 guint
44 wmem_list_count(const wmem_list_t *list)
46 return list->count;
49 wmem_list_frame_t *
50 wmem_list_head(const wmem_list_t *list)
52 return list->head;
55 wmem_list_frame_t *
56 wmem_list_tail(const wmem_list_t *list)
58 return list->tail;
61 wmem_list_frame_t *
62 wmem_list_frame_next(const wmem_list_frame_t *frame)
64 return frame->next;
67 wmem_list_frame_t *
68 wmem_list_frame_prev(const wmem_list_frame_t *frame)
70 return frame->prev;
73 void *
74 wmem_list_frame_data(const wmem_list_frame_t *frame)
76 return frame->data;
79 void
80 wmem_list_remove(wmem_list_t *list, void *data)
82 wmem_list_frame_t *frame;
84 frame = list->head;
86 while (frame && frame->data != data) {
87 frame = frame->next;
90 if (frame == NULL) {
91 return;
94 wmem_list_remove_frame(list, frame);
97 void
98 wmem_list_remove_frame(wmem_list_t *list, wmem_list_frame_t *frame)
100 if (frame->prev) {
101 frame->prev->next = frame->next;
103 else {
104 list->head = frame->next;
107 if (frame->next) {
108 frame->next->prev = frame->prev;
110 else {
111 list->tail = frame->prev;
114 list->count--;
115 wmem_free(list->allocator, frame);
118 void
119 wmem_list_prepend(wmem_list_t *list, void *data)
121 wmem_list_frame_t *new_frame;
123 new_frame = wmem_new(list->allocator, wmem_list_frame_t);
125 new_frame->data = data;
126 new_frame->next = list->head;
127 new_frame->prev = NULL;
129 if (list->head) {
130 list->head->prev = new_frame;
132 else {
133 list->tail = new_frame;
136 list->head = new_frame;
137 list->count++;
140 void
141 wmem_list_append(wmem_list_t *list, void *data)
143 wmem_list_frame_t *new_frame;
145 new_frame = wmem_new(list->allocator, wmem_list_frame_t);
146 new_frame->data = data;
147 new_frame->next = NULL;
148 new_frame->prev = list->tail;
150 if (list->tail) {
151 list->tail->next = new_frame;
153 else {
154 list->head = new_frame;
157 list->tail = new_frame;
158 list->count++;
161 wmem_list_t *
162 wmem_list_new(wmem_allocator_t *allocator)
164 wmem_list_t *list;
166 list = wmem_new(allocator, wmem_list_t);
168 list->count = 0;
169 list->head = NULL;
170 list->tail = NULL;
171 list->allocator = allocator;
173 return list;
177 * Editor modelines - http://www.wireshark.org/tools/modelines.html
179 * Local variables:
180 * c-basic-offset: 4
181 * tab-width: 8
182 * indent-tabs-mode: nil
183 * End:
185 * vi: set shiftwidth=4 tabstop=8 expandtab:
186 * :indentSize=4:tabSize=8:noTabs=true: