Loading...
Searching...
No Matches
list.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
3 * 2016 TriaGnoSys GmbH
4 *
5 * This file is subject to the terms and conditions of the GNU Lesser
6 * General Public License v2.1. See the file LICENSE in the top level
7 * directory for more details.
8 */
9
23#ifndef LIST_H
24#define LIST_H
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
40typedef struct list_node {
41 struct list_node *next;
43
53static inline void list_add(list_node_t *node, list_node_t *new_node)
54{
55 new_node->next = node->next;
56 node->next = new_node;
57}
58
68{
69 list_node_t *head = list->next;
70
71 if (head) {
72 list->next = head->next;
73 }
74 return head;
75}
76
86static inline list_node_t *list_remove(list_node_t *list, list_node_t *node)
87{
88 while (list->next) {
89 if (list->next == node) {
90 list->next = node->next;
91 return node;
92 }
93 list = list->next;
94 }
95 return list->next;
96}
97
98#ifdef __cplusplus
99}
100#endif
101
102#endif /* LIST_H */
static list_node_t * list_remove_head(list_node_t *list)
Removes the head of the list and returns it.
Definition list.h:67
struct list_node list_node_t
List node structure.
static void list_add(list_node_t *node, list_node_t *new_node)
Insert object into list.
Definition list.h:53
static list_node_t * list_remove(list_node_t *list, list_node_t *node)
Removes the node from the list.
Definition list.h:86
List node structure.
Definition list.h:40
struct list_node * next
pointer to next list entry
Definition list.h:41