1 /* list.h -- doubly linked list header file for vlock,
2 * the VT locking program for linux
4 * This program is copyright (C) 2007 Frank Benkstein, and is free
5 * software which is freely distributable under the terms of the
6 * GNU General Public License version 2, included as the file COPYING in this
7 * distribution. It is NOT public domain software, and any
8 * redistribution not permitted by the GNU General Public License is
9 * expressly forbidden without prior written permission from
17 struct list_item
*next
;
18 struct list_item
*previous
;
23 struct list_item
*first
;
24 struct list_item
*last
;
27 struct list
*list_new(void);
28 void list_free(struct list
*l
);
30 size_t list_length(struct list
*l
);
31 void list_append(struct list
*l
, void *data
);
33 #define list_for_each(list, item) \
34 for (struct list_item *item = (list)->first; item != NULL; item = item->next)
38 /* Inspired by the doubly linked list code from glib:
40 * GLIB - Library of useful routines for C programming
41 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
43 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
44 * file for a list of people on the GLib Team. See the ChangeLog
45 * files for a list of changes. These files are distributed with
46 * GLib at ftp://ftp.gtk.org/pub/gtk/.
49 /* An item of the list.
51 * Any item also represents the full list.
53 * An empty list is represented by the NULL pointer.
58 struct List
*previous
;
61 /* Get the first item of the list. Returns the first item of the list or NULL
62 * if the list is empty. */
63 struct List
*list_first(struct List
*list
);
65 /* Get the last item of the list. Returns the last item of the list or NULL if
66 * the list is empty. */
67 struct List
*list_last(struct List
*list
);
69 /* Get the next item. Returns the item after the given item or NULL if the
71 struct List
*list_next(struct List
*list
);
73 /* Get the previous item. Returns the item before the given item or NULL if
74 * the list is empty. */
75 struct List
*list_previous(struct List
*list
);
77 /* Allocate a new list item with the given data pointer and append it to the
78 * end of the list. Returns the new start of the list. Calls abort() on
80 struct List
*list_append(struct List
*list
, void *data
);
82 /* Removes the first item with the given data pointer and deletes it from the
83 * list. Returns the new start of the list. Does not free the data. */
84 struct List
*list_remove(struct List
*list
, void *data
);
86 /* Delete one item from the list. Returns the new start of the list. */
87 struct List
*list_delete_link(struct List
*list
, struct List
*item
);
89 /* Returns the first item with the given data pointer or NULL if none is found.
91 struct List
*list_find(struct List
*list
, void *data
);
93 /* Make a copy of the list. Returns a shallow copy of the entire list. Calls
94 * abort() on memory error. */
95 struct List
*list_copy(struct List
*list
);
97 /* Free the entire list. Does free the items'. */
98 void list_free(struct List
*list
);
100 #define list_for_each(list, item) \
101 for (struct List *item = list_first(list); item != NULL; item = list_next(item))
103 #define list_reverse_for_each(list, item) \
104 for (struct List *item = list_last(plugins); item != NULL; item = list_previous(item))