Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
list.h File Reference
#include <stdbool.h>
Include dependency graph for list.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ListItem
 
struct  List
 

Typedefs

typedef void(* FreeItemFn) (void *)
 
typedef bool(* CompareItemFn) (void *, void *)
 
typedef void(* IteratorFn) (void *)
 
typedef struct ListItem ListItem
 

Functions

void list_create (List *list, int item_size, FreeItemFn free_item_fn)
 
void list_destroy (List *list)
 
bool list_prepend (List *list, void *item)
 
bool list_append (List *list, void *item)
 
ListItemlist_get (List *list, void *data, CompareItemFn compare_item_fn)
 
void list_delete (List *list, ListItem *item)
 
void list_iterate (List *list, IteratorFn iterator_fn)
 

Typedef Documentation

◆ CompareItemFn

typedef bool(* CompareItemFn) (void *, void *)

Definition at line 24 of file list.h.

◆ FreeItemFn

typedef void(* FreeItemFn) (void *)

Definition at line 22 of file list.h.

◆ IteratorFn

typedef void(* IteratorFn) (void *)

Definition at line 26 of file list.h.

◆ ListItem

typedef struct ListItem ListItem

Definition at line 28 of file list.h.

Function Documentation

◆ list_append()

bool list_append ( List * list,
void * item )

Definition at line 78 of file list.c.

78 {
79
80 ListItem *node = calloc(1, sizeof(ListItem));
81 if (node == NULL) {
82 return false;
83 }
84
85 node->data = calloc(1, list->item_size);
86 if (node->data == NULL) {
87 free(node);
88 return false;
89 }
90
91 memcpy(node->data, item, list->item_size);
92
93 if (list->length == 0) {
94 list->head = node;
95 list->tail = node;
96 } else {
97 list->tail->next = node;
98 list->tail = node;
99 }
100
101 list->length++;
102 return true;
103}
void * data
Definition list.h:31
memcpy((char *) pInfo->slotDescription, s, l)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_create()

void list_create ( List * list,
int item_size,
FreeItemFn free_item_fn )

Definition at line 24 of file list.c.

24 {
25
26 list->length = 0;
27 list->item_size = item_size;
28 list->head = NULL;
29 list->tail = NULL;
30 list->free_item_fn = free_item_fn;
31}
Here is the caller graph for this function:

◆ list_delete()

void list_delete ( List * list,
ListItem * item )

Definition at line 117 of file list.c.

117 {
118
119 if (item == NULL) {
120
121 return;
122 }
123
124 if (item == list->head) {
125 if (list->head == list->tail) {
126 list->head = NULL;
127 list->tail = NULL;
128 } else {
129 list->head = list->head->next;
130 }
131
132 if (list->free_item_fn) {
133 list->free_item_fn(item->data);
134 }
135 insecure_memzero(item->data, list->item_size);
136 free(item->data);
137 free(item);
138 } else if (item == list->tail) {
139 for (ListItem *i = list->head; i != NULL; i = i->next) {
140 if (i->next == list->tail) {
141 list->tail = i;
142 i->next = NULL;
143
144 if (list->free_item_fn) {
145 list->free_item_fn(item->data);
146 }
147 insecure_memzero(item->data, list->item_size);
148 free(item->data);
149 free(item);
150 }
151 }
152 } else {
153 if (list->free_item_fn) {
154 list->free_item_fn(item->data);
155 }
156
157 ListItem *tmp = item->next;
158
159 insecure_memzero(item->data, list->item_size);
160 free(item->data);
161
162 item->data = item->next->data;
163 item->next = item->next->next;
164
165 if (tmp == list->tail) {
166 list->tail = item;
167 }
168
169 free(tmp);
170 }
171
172 list->length--;
173}
#define insecure_memzero(buf, len)
ListItem * next
Definition list.h:32
Here is the caller graph for this function:

◆ list_destroy()

void list_destroy ( List * list)

Definition at line 33 of file list.c.

33 {
34
35 ListItem *current;
36
37 while (list->head != NULL) {
38 current = list->head;
39 list->head = current->next;
40
41 if (list->free_item_fn) {
42 list->free_item_fn(current->data);
43 }
44
45 insecure_memzero(current->data, list->item_size);
46 free(current->data);
47 free(current);
48 }
49}
Here is the caller graph for this function:

◆ list_get()

ListItem * list_get ( List * list,
void * data,
CompareItemFn compare_item_fn )

Definition at line 105 of file list.c.

105 {
106
107 for (ListItem *item = list->head; item != NULL; item = item->next) {
108 if (compare_item_fn(data, item->data) == true) {
109
110 return item;
111 }
112 }
113
114 return NULL;
115}
Here is the caller graph for this function:

◆ list_iterate()

void list_iterate ( List * list,
IteratorFn iterator_fn )

Definition at line 175 of file list.c.

175 {
176
177 for (ListItem *item = list->head; item != NULL; item = item->next) {
178 iterator_fn(item->data);
179 }
180}
Here is the caller graph for this function:

◆ list_prepend()

bool list_prepend ( List * list,
void * item )

Definition at line 51 of file list.c.

51 {
52
53 ListItem *node = calloc(1, sizeof(ListItem));
54 if (node == NULL) {
55 return false;
56 }
57
58 node->data = calloc(1, list->item_size);
59
60 if (node->data == NULL) {
61 free(node);
62 return false;
63 }
64
65 memcpy(node->data, item, list->item_size);
66
67 node->next = list->head;
68 list->head = node;
69
70 if (list->tail == NULL) {
71 list->tail = list->head;
72 }
73
74 list->length++;
75 return true;
76}
Here is the call graph for this function: