All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
10#pragma once
11
25#ifdef __cplusplus
26extern "C" {
27#endif
28
39typedef struct list_node {
40 struct list_node *next;
42
52static inline void list_add(list_node_t *node, list_node_t *new_node)
53{
54 new_node->next = node->next;
55 node->next = new_node;
56}
57
67{
68 list_node_t *head = list->next;
69
70 if (head) {
71 list->next = head->next;
72 }
73 return head;
74}
75
85static inline list_node_t *list_remove(list_node_t *list, list_node_t *node)
86{
87 while (list->next) {
88 if (list->next == node) {
89 list->next = node->next;
90 return node;
91 }
92 list = list->next;
93 }
94 return list->next;
95}
96
97#ifdef __cplusplus
98}
99#endif
100
static list_node_t * list_remove_head(list_node_t *list)
Removes the head of the list and returns it.
Definition list.h:66
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:52
static list_node_t * list_remove(list_node_t *list, list_node_t *node)
Removes the node from the list.
Definition list.h:85
List node structure.
Definition list.h:39
struct list_node * next
pointer to next list entry
Definition list.h:40