2
Implementation of a doubly linked list.
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
This program is released under the GPL with the additional exemption
19
that compiling, linking, and/or using OpenSSL is allowed.
21
Copyright (C) 2008 Bertrand Mesot <http://www.objectif-securite.ch>
28
/*-------------------------------------------------------------------------*/
29
list_t *list_alloc(void) {
30
list_t *l = (list_t*)malloc(sizeof(list_t));
38
/*-------------------------------------------------------------------------*/
39
void list_free(list_t *l) {
43
/*-------------------------------------------------------------------------*/
44
void list_clean(list_t *l) {
48
/*-------------------------------------------------------------------------*/
49
void list_add_head(list_t *l, void *data) {
50
list_nd_t *nd = list_nd_alloc(data);
51
list_nd_t *old = l->head;
62
/*-------------------------------------------------------------------------*/
63
void list_add_tail(list_t *l, void *data) {
64
list_nd_t *nd = list_nd_alloc(data);
65
list_nd_t *old = l->tail;
76
/*-------------------------------------------------------------------------*/
77
void *list_rem_head(list_t *l) {
78
list_nd_t *nd = l->head;
80
if (nd == 0) return 0;
82
list_nd_t *old = nd->prev;
92
return list_nd_free(nd);
94
/*-------------------------------------------------------------------------*/
95
void *list_rem_tail(list_t *l) {
96
list_nd_t *nd = l->tail;
98
if (nd == 0) return 0;
100
list_nd_t *old = nd->next;
110
return list_nd_free(nd);
112
/*-------------------------------------------------------------------------*/
113
list_nd_t *list_nd_alloc(void *data) {
114
list_nd_t *nd = (list_nd_t*)malloc(sizeof(list_nd_t));
122
/*-------------------------------------------------------------------------*/
123
void *list_nd_free(list_nd_t *nd) {
124
void *data = nd->data;