Patrick Georgi | afd4c87 | 2020-05-05 23:43:18 +0200 | [diff] [blame] | 1 | /* Taken from depthcharge: src/base/list.c */ |
Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Patrick Rudolph | 67aca3e | 2018-04-12 11:44:43 +0200 | [diff] [blame] | 3 | |
Patrick Rudolph | 666c172 | 2018-04-03 09:57:33 +0200 | [diff] [blame] | 4 | #include <list.h> |
Patrick Rudolph | 67aca3e | 2018-04-12 11:44:43 +0200 | [diff] [blame] | 5 | |
Patrick Rudolph | 666c172 | 2018-04-03 09:57:33 +0200 | [diff] [blame] | 6 | void list_remove(struct list_node *node) |
Patrick Rudolph | 67aca3e | 2018-04-12 11:44:43 +0200 | [diff] [blame] | 7 | { |
| 8 | if (node->prev) |
| 9 | node->prev->next = node->next; |
| 10 | if (node->next) |
| 11 | node->next->prev = node->prev; |
| 12 | } |
| 13 | |
Patrick Rudolph | 666c172 | 2018-04-03 09:57:33 +0200 | [diff] [blame] | 14 | void list_insert_after(struct list_node *node, struct list_node *after) |
Patrick Rudolph | 67aca3e | 2018-04-12 11:44:43 +0200 | [diff] [blame] | 15 | { |
| 16 | node->next = after->next; |
| 17 | node->prev = after; |
| 18 | after->next = node; |
| 19 | if (node->next) |
| 20 | node->next->prev = node; |
| 21 | } |
| 22 | |
Patrick Rudolph | 666c172 | 2018-04-03 09:57:33 +0200 | [diff] [blame] | 23 | void list_insert_before(struct list_node *node, struct list_node *before) |
Patrick Rudolph | 67aca3e | 2018-04-12 11:44:43 +0200 | [diff] [blame] | 24 | { |
| 25 | node->prev = before->prev; |
| 26 | node->next = before; |
| 27 | before->prev = node; |
| 28 | if (node->prev) |
| 29 | node->prev->next = node; |
| 30 | } |