2 * Copyright (c) 2013, Olivier MATZ <zer0@droids-corp.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the University of California, Berkeley nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * This module is a list implementation, based on TAILQ from
36 * sys/queue.h -see queue(3)-. It handles the allocation of chaining
37 * structure so any kind of element can be chained.
39 * To be really useful, this API must be used in conjonction with the
40 * TAILQ_* macros. For instance, to browse the list:
42 * struct cfzy_list_elt *e;
43 * TAILQ_FOREACH(e, list_head, next) {
49 #include <sys/queue.h>
54 TAILQ_HEAD(cfzy_list_head, cfzy_list_elt);
57 * A list element, used to chain objects together. This structure is
58 * allocated by cfzy_list_add().
60 struct cfzy_list_elt {
61 TAILQ_ENTRY(cfzy_list_elt) next;
66 * Insert an element at the tail of the list
68 * Allocate a cfzy_list_elt structure, set its ptr field and insert it
69 * at the tail of the list.
72 * List head to insert the element
74 * Pointer to the object that will be referenced by list_elt->ptr
76 * 0 on succes, and negative on error
78 int cfzy_list_add_tail(struct cfzy_list_head *list, void *ptr);
81 * Insert an element at the head of the list
83 * Allocate a cfzy_list_elt structure, set its ptr field and insert it
84 * at the head of the list.
87 * List head to insert the element
89 * Pointer to the object that will be referenced by list_elt->ptr
91 * 0 on succes, and negative on error
93 int cfzy_list_add_head(struct cfzy_list_head *list, void *ptr);
96 * Remove an element from the list
98 * Unchain the cfzy_list_elt structure and free it.
101 * List head to insert the element
105 void cfzy_list_del(struct cfzy_list_head *list, struct cfzy_list_elt *elt);
108 * Check if an element is in the list
110 * Browse the list and check if there is already an cfzy_list_elt
111 * structure referencing ptr.
116 * Pointer to the element
118 * 1 if the element is in list, else 0
120 int cfzy_list_elt_is_in_list(const struct cfzy_list_head *list, const void *ptr);
123 * Allocate a new list
126 * Pointer to the new list head, or NULL on error
128 struct cfzy_list_head *cfzy_list_alloc(void);
133 * Free all cfzy_list_elt of the list using the free_fct if provided,
134 * then free the cfzy_list_head structure.
139 * Function to free an element
141 void cfzy_list_free(struct cfzy_list_head *list, void (*free_fct)(void *));
143 #endif /* _CFZY_LIST_H_ */