list.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016 Kaspar Schleiser <kaspar@schleiser.de>
3  * SPDX-FileCopyrightText: 2016 TriaGnoSys GmbH
4  * SPDX-License-Identifier: LGPL-2.1-only
5  */
6 
7 #pragma once
8 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
36 typedef struct list_node {
37  struct list_node *next;
39 
49 static inline void list_add(list_node_t *node, list_node_t *new_node)
50 {
51  new_node->next = node->next;
52  node->next = new_node;
53 }
54 
64 {
65  list_node_t *head = list->next;
66 
67  if (head) {
68  list->next = head->next;
69  }
70  return head;
71 }
72 
82 static inline list_node_t *list_remove(list_node_t *list, list_node_t *node)
83 {
84  while (list->next) {
85  if (list->next == node) {
86  list->next = node->next;
87  return node;
88  }
89  list = list->next;
90  }
91  return list->next;
92 }
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 
static list_node_t * list_remove(list_node_t *list, list_node_t *node)
Removes the node from the list.
Definition: list.h:82
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:49
static list_node_t * list_remove_head(list_node_t *list)
Removes the head of the list and returns it.
Definition: list.h:63
List node structure.
Definition: list.h:36
struct list_node * next
pointer to next list entry
Definition: list.h:37