Browse Source

core/list: add remove method

pr/spi.typo
Victor Arino 6 years ago
parent
commit
be146741c9
  1. 23
      core/include/list.h

23
core/include/list.h

@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
* 2016 TriaGnoSys GmbH
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
@ -16,6 +17,7 @@
* Lists are represented as element pointing to the first actual list element.
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Víctor Ariño <victor.arino@zii.aero>
*/
#ifndef LIST_H
@ -69,6 +71,27 @@ static inline list_node_t* list_remove_head(list_node_t *list) {
return head;
}
/**
* @brief Removes the node from the list
*
* @param[in] list Pointer to the list itself, where list->next points
* to the root node
* @param[in] node List node to remove from the list
*
* @return removed node, or NULL if empty or not found
*/
static inline list_node_t *list_remove(list_node_t *list, list_node_t *node)
{
while (list->next) {
if (list->next == node) {
list->next = node->next;
return node;
}
list = list->next;
}
return list->next;
}
#ifdef __cplusplus
}
#endif

Loading…
Cancel
Save