4 Copyright (C) 2000-2004 Ivo Timmermans <ivo@tinc-vpn.org>
5 2000-2004 Guus Sliepen <guus@tinc-vpn.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 $Id: list.h 1374 2004-03-21 14:21:22Z guus $
27 typedef struct list_node {
28 struct list_node *prev;
29 struct list_node *next;
34 typedef void (*list_action_t)(const void *);
35 typedef void (*list_node_action_t)(const list_node_t *);
38 struct list_node *head;
39 struct list_node *tail;
45 /* (De)constructors */
47 extern struct list *list_new(list_action_t) __attribute__ ((__malloc__));
48 extern void list_free(struct list *);
49 extern struct list_node *list_node_new(void);
50 extern void list_node_free(struct list *, struct list_node *);
52 /* Insertion and deletion */
54 extern struct list_node *list_add_head(struct list *, void *);
55 extern struct list_node *list_add_tail(struct list *, void *);
57 extern void list_unlink_node(struct list *, struct list_node *);
58 extern void list_node_del(struct list *, struct list_node *);
60 extern void list_del_head(struct list *);
61 extern void list_del_tail(struct list *);
63 /* Head/tail lookup */
65 extern void *list_get_head(const struct list *);
66 extern void *list_get_tail(const struct list *);
68 /* Fast list deletion */
70 extern void list_del(struct list *);
74 #define list_foreach(list, object, action) {list_node_t *_node, *_next; \
75 for(_node = (list)->head; _node; _node = _next) { \
76 _next = _node->next; \
77 (object) = _node->data; \
82 #define list_foreach_node(list, node, action) {list_node_t *_next; \
83 for((node) = (list)->head; (node); (node) = _next) { \
84 _next = (node)->next; \