blob: 06d422d30eb5c3c3d76e09bed3ed761847b4b1dd [file] [log] [blame]
Patrick Rudolph67aca3e2018-04-12 11:44:43 +02001/*
2 * Copyright 2012 Google Inc.
Patrick Rudolph666c1722018-04-03 09:57:33 +02003 * Copyright 2018-present Facebook, Inc.
Patrick Rudolph67aca3e2018-04-12 11:44:43 +02004 *
Patrick Rudolph666c1722018-04-03 09:57:33 +02005 * Taken from depthcharge: src/base/list.c
Patrick Rudolph67aca3e2018-04-12 11:44:43 +02006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but without any warranty; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
Patrick Rudolph666c1722018-04-03 09:57:33 +020018#include <list.h>
Patrick Rudolph67aca3e2018-04-12 11:44:43 +020019
Patrick Rudolph666c1722018-04-03 09:57:33 +020020void list_remove(struct list_node *node)
Patrick Rudolph67aca3e2018-04-12 11:44:43 +020021{
22 if (node->prev)
23 node->prev->next = node->next;
24 if (node->next)
25 node->next->prev = node->prev;
26}
27
Patrick Rudolph666c1722018-04-03 09:57:33 +020028void list_insert_after(struct list_node *node, struct list_node *after)
Patrick Rudolph67aca3e2018-04-12 11:44:43 +020029{
30 node->next = after->next;
31 node->prev = after;
32 after->next = node;
33 if (node->next)
34 node->next->prev = node;
35}
36
Patrick Rudolph666c1722018-04-03 09:57:33 +020037void list_insert_before(struct list_node *node, struct list_node *before)
Patrick Rudolph67aca3e2018-04-12 11:44:43 +020038{
39 node->prev = before->prev;
40 node->next = before;
41 before->prev = node;
42 if (node->prev)
43 node->prev->next = node;
44}