utils/list.h File Reference

Go to the source code of this file.

Data Structures

struct  list_head
struct  list_s

Defines

#define LIST_HEAD_INIT(name)   { &(name), &(name) }
#define LIST_HEAD(name)   struct list_head name = LIST_HEAD_INIT(name)
#define INIT_LIST_HEAD(ptr)
#define list_entry(ptr, type, member)   ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
#define list_for_each(pos, head)
#define list_for_each_prev(pos, head)
#define list_for_each_safe(pos, n, head)

Typedefs

typedef struct list_head list_head_t
typedef struct list_s list_t

Functions

void list_add (struct list_head *new_element, struct list_head *head)
void list_add_tail (struct list_head *new_element, struct list_head *head)
void list_del (struct list_head *entry)
void list_del_init (struct list_head *entry)
void list_move (struct list_head *list, struct list_head *head)
void list_move_tail (struct list_head *list, struct list_head *head)
void list_splice (struct list_head *list, struct list_head *head)
void list_splice_init (struct list_head *list, struct list_head *head)
int list_empty (struct list_head *head)
list_tlist_get_new_node (void *data)
 Create new list node with given data.
list_tlist_get_first_prev_node (list_t *list)
 Just get first previous element from list.
list_tlist_get_next_node (list_t *list, list_t *previous_node, void **out_data)
 Gets next node for given node.
list_tlist_get_new_list ()
 Create and init list, it's node with null data.
list_tlist_get_new_list_if_null (list_t *list)
 Create and init list, it is node with null data.
void list_free (list_t *list)
 Free list, without nodes. Nodes not freed.
list_tlist_free_empty (list_t *list)
 Free list.
void list_free_node (list_t *node, void(*free_data_func)(void *data))
 Free node.
void list_free_with_nodes (list_t *list, void(*free_data_func)(void *data))
 Free list and all nodes.
void list_del_and_free_nodes_with_data (list_t *list, void *ref_to_data, void(*free_data_func)(void *data))
 Free nodes with give data.
void list_del_and_free_node (list_t *node, void(*free_data_func)(void *data))
 Removes node from list and free it.
void list_add_node (list_t *new_node, list_t *list)
 Add a new entry.
void list_add_data (void *data, list_t *list)
 Add a new entry.
void list_add_list (list_t *list, list_t *node)
 Add one list to another.
list_tlist_copy_list (list_t *list)
 Create new list from another.
int list_is_empty (list_t *list)
 Tests whether a list is empty.
int list_is_null_or_empty (list_t *list)
 Tests whether a list is empty or equals NULL.
int list_is_last_node (list_t *list, list_t *node)
 Tests whether a node is last in the list.
int list_count_nodes_with_data (list_t *list, void *ref_to_data)
 Count nodes with given reference to data.


Define Documentation

#define INIT_LIST_HEAD ( ptr   ) 

Value:

do { \
        (ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)

#define list_entry ( ptr,
type,
member   )     ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))

list_entry - get the struct for this entry : the &struct list_head pointer. : the type of the struct this is embedded in. : the name of the list_struct within the struct.

#define list_for_each ( pos,
head   ) 

Value:

for (pos = (head)->next; pos != (head); \
                pos = pos->next)
list_for_each - iterate over a list : the &struct list_head to use as a loop counter. : the head for your list.

#define list_for_each_prev ( pos,
head   ) 

Value:

for (pos = (head)->prev; pos != (head); \
                pos = pos->prev)
list_for_each_prev - iterate over a list backwards : the &struct list_head to use as a loop counter. : the head for your list.

#define list_for_each_safe ( pos,
n,
head   ) 

Value:

for (pos = (head)->next, n = pos->next; pos != (head); \
                pos = n, n = pos->next)
list_for_each_safe - iterate over a list safe against removal of list entry : the &struct list_head to use as a loop counter.
: another &struct list_head to use as temporary storage : the head for your list.

#define LIST_HEAD ( name   )     struct list_head name = LIST_HEAD_INIT(name)

#define LIST_HEAD_INIT ( name   )     { &(name), &(name) }


Typedef Documentation

typedef struct list_head list_head_t

typedef struct list_s list_t


Function Documentation

void list_add ( struct list_head new,
struct list_head head 
)

list_for_each_entry - iterate over list of given type : the type * to use as a loop counter. : the head for your list. : the name of the list_struct within the struct. list_for_each_entry_safe - iterate over list of given type safe against removal of list entry : the type * to use as a loop counter.
: another type * to use as temporary storage : the head for your list. : the name of the list_struct within the struct.

list_add - add a new entry : new entry to be added : list head to add it after

Insert a new entry after the specified head. This is good for implementing stacks.

void list_add_data ( void *  data,
list_t list 
)

Add a new entry.

Create new node with given data and add it to list. Insert a new entry after the specified head. This is good for implementing stacks.

Parameters:
data data for new node.
list list head to add it after.

void list_add_list ( list_t list,
list_t node 
)

Add one list to another.

It not delete a list_t struct of addedd list, you need to remove it by youself, don't delete nodes (use

See also:
list_free()) or you can reinit list and use it as new empty list.
Parameters:
list the new list to add.
node the place to add it in the first list.

void list_add_node ( list_t new_node,
list_t list 
)

Add a new entry.

Insert a new entry after the specified head. This is good for implementing stacks.

Parameters:
new_node entry to be added.
list list head to add it after.

void list_add_tail ( struct list_head new,
struct list_head head 
)

list_add_tail - add a new entry : new entry to be added : list head to add it before

Insert a new entry before the specified head. This is useful for implementing queues.

list_t* list_copy_list ( list_t list  ) 

Create new list from another.

It create new list and set node's data field equals given list's nodes data (memory not allocating for data fields, sets references).

Parameters:
list list for copy.
Returns:
new list on success or NULL otherwise.

int list_count_nodes_with_data ( list_t list,
void *  ref_to_data 
)

Count nodes with given reference to data.

Parameters:
list list for check.
ref_to_data reference to data.
Returns:
quantity of nodes.

void list_del ( struct list_head entry  ) 

list_del - deletes entry from list. : the element to delete from the list. Note: list_empty on entry does not return true after this, the entry is in an undefined state.

void list_del_and_free_node ( list_t node,
void(*)(void *data)  free_data_func 
)

Removes node from list and free it.

Parameters:
node node for remove and free.
free_data_func reference for node data free function or NULL.

void list_del_and_free_nodes_with_data ( list_t list,
void *  ref_to_data,
void(*)(void *data)  free_data_func 
)

Free nodes with give data.

If node has a data field with reference equals given, it will be removed.

Parameters:
list list for check.
ref_to_data reference to data or NULL, all nodes with data field equals NULL will be removed.
free_data_func reference for node data free function or NULL.

void list_del_init ( struct list_head entry  ) 

list_del_init - deletes entry from list and reinitialize it. : the element to delete from the list.

int list_empty ( struct list_head head  ) 

list_empty - tests whether a list is empty : the list to test.

void list_free ( list_t list  ) 

Free list, without nodes. Nodes not freed.

Parameters:
list list.

list_t* list_free_empty ( list_t list  ) 

Free list.

Free list only if list is empty, no nodes.

Parameters:
list list.
Returns:
list or NULL if it was freed.

void list_free_node ( list_t node,
void(*)(void *data)  free_data_func 
)

Free node.

Parameters:
node node for free.
free_data_func reference for node data free function or NULL.

void list_free_with_nodes ( list_t list,
void(*)(void *data)  free_data_func 
)

Free list and all nodes.

Parameters:
list list for free.
free_data_func reference for node data free function or NULL.

list_t* list_get_first_prev_node ( list_t list  ) 

Just get first previous element from list.

Parameters:
list list of elements.
Returns:
list element.

list_t* list_get_new_list (  ) 

Create and init list, it's node with null data.

Returns:
new created list.

list_t* list_get_new_list_if_null ( list_t list  ) 

Create and init list, it is node with null data.

Create new list if given equals NULL, otherwise return given list.

Parameters:
list list for check.
Returns:
new created list or given list if it not NULL.

list_t* list_get_new_node ( void *  data  ) 

Create new list node with given data.

Parameters:
data for storage in the node.
Returns:
new list element on success or NULL otherwise.

list_t* list_get_next_node ( list_t list,
list_t previous_node,
void **  out_data 
)

Gets next node for given node.

Gets next node, if previous_node equals NULL or it last element in list, it gets firs element.

Parameters:
list list.
previous_node node for get next node in the list or NULL.
out_data if not NULL, it will be equals a data field of new (next) node. It will be NULL if list equals NULL or empty.
Returns:
node after previous_node or NULL if list equals NULL or empty.

int list_is_empty ( list_t list  ) 

Tests whether a list is empty.

Parameters:
list the list to test.
Returns:
1 if list is empty, or 0 otherwise.

int list_is_last_node ( list_t list,
list_t node 
)

Tests whether a node is last in the list.

Parameters:
list the list to test.
node node to test.
Returns:
-1 on error (list or node equals NULL), 0 - node is not last, 1 - last.

int list_is_null_or_empty ( list_t list  ) 

Tests whether a list is empty or equals NULL.

Parameters:
list the list to test.
Returns:
1 if list is empty or NULL, or 0 otherwise.

void list_move ( struct list_head list,
struct list_head head 
)

list_move - delete from one list and add as another's head : the entry to move : the head that will precede our entry

void list_move_tail ( struct list_head list,
struct list_head head 
)

list_move_tail - delete from one list and add as another's tail : the entry to move : the head that will follow our entry

void list_splice ( struct list_head list,
struct list_head head 
)

list_splice - join two lists : the new list to add. : the place to add it in the first list.

void list_splice_init ( struct list_head list,
struct list_head head 
)

list_splice_init - join two lists and reinitialise the emptied list. : the new list to add. : the place to add it in the first list.

The list at is reinitialised


doxygen