| 1 | /* |
| 2 | * Copyright (C) 2006-2012 B.A.T.M.A.N. contributors: |
| 3 | * |
| 4 | * Marek Lindner |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of version 2 of the GNU General Public |
| 8 | * License as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 18 | * 02110-1301, USA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | |
| 23 | |
| 24 | #include "list-batman.h"cxx . . $ `<file>/list-batman.h`/ |
| 25 | |
| 26 | |
| 27 | |
| 28 | /* |
| 29 | * Insert a new entry between two known consecutive entries. |
| 30 | * |
| 31 | * This is only for internal list manipulation where we know |
| 32 | * the next entries already! |
| 33 | */ |
| 34 | static void __list_addcxx . . $ __list_add(a574ce21b3779bd1).( struct list_headcxx . . $ list_head# *new, struct list_headcxx . . $ list_head# *prev, struct list_headcxx . . $ list_head# *next ) { |
| 35 | |
| 36 | new->nextcxx . . $ list_head#next. = next; |
| 37 | prev->nextcxx . . $ list_head#next. = new; |
| 38 | |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * list_add - add a new entry |
| 43 | * @new: new entry to be added |
| 44 | * @head: list head to add it after |
| 45 | * |
| 46 | * Insert a new entry after the specified head. |
| 47 | * This is good for implementing stacks. |
| 48 | */ |
| 49 | void list_addcxx . . $ list_add(c9932e5dfcae05fa).( struct list_headcxx . . $ list_head# *new, struct list_head_firstcxx . . $ list_head_first# *head ) { |
| 50 | |
| 51 | __list_addcxx . . $ __list_add(a574ce21b3779bd1).( new, (struct list_headcxx . . $ list_head# *)head, head->nextcxx . . $ list_head_first#next. ); |
| 52 | |
| 53 | if ( head->prevcxx . . $ list_head_first#prev. == (struct list_headcxx . . $ list_head# *)head ) |
| 54 | head->prevcxx . . $ list_head_first#prev. = new; |
| 55 | |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * list_add_tail - add a new entry |
| 60 | * @new: new entry to be added |
| 61 | * @head: list head to add it before |
| 62 | * |
| 63 | * Insert a new entry before the specified head. |
| 64 | * This is useful for implementing queues. |
| 65 | */ |
| 66 | void list_add_tailcxx . . $ list_add_tail(c9932e5dfcae05fa).( struct list_headcxx . . $ list_head# *new, struct list_head_firstcxx . . $ list_head_first# *head ) { |
| 67 | |
| 68 | __list_addcxx . . $ __list_add(a574ce21b3779bd1).( new, head->prevcxx . . $ list_head_first#prev., (struct list_headcxx . . $ list_head# *)head ); |
| 69 | |
| 70 | head->prevcxx . . $ list_head_first#prev. = new; |
| 71 | |
| 72 | } |
| 73 | |
| 74 | void list_add_beforecxx . . $ list_add_before(a574ce21b3779bd1).( struct list_headcxx . . $ list_head# *prev_node, struct list_headcxx . . $ list_head# *next_node, struct list_headcxx . . $ list_head# *new_node ) { |
| 75 | |
| 76 | prev_node->nextcxx . . $ list_head#next. = new_node; |
| 77 | new_node->nextcxx . . $ list_head#next. = next_node; |
| 78 | |
| 79 | } |
| 80 | |
| 81 | |
| 82 | |
| 83 | /* |
| 84 | * Delete a list entry by making the next entries |
| 85 | * point to each other. |
| 86 | * |
| 87 | * This is only for internal list manipulation where we know |
| 88 | * the next entries already! |
| 89 | */ |
| 90 | static void __list_delcxx . . $ __list_del(6c3f7387ec573de3).( struct list_headcxx . . $ list_head# *prev, struct list_headcxx . . $ list_head# *next ) { |
| 91 | |
| 92 | prev->nextcxx . . $ list_head#next. = next; |
| 93 | |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * list_del - deletes entry from list. |
| 98 | * @entry: the element to delete from the list. |
| 99 | * Note: list_empty on entry does not return true after this, the entry is in an undefined state. |
| 100 | */ |
| 101 | void list_delcxx . . $ list_del(68233758eccab105).( struct list_headcxx . . $ list_head# *prev_entry, struct list_headcxx . . $ list_head# *entry, struct list_head_firstcxx . . $ list_head_first# *head ) { |
| 102 | |
| 103 | if ( head->prevcxx . . $ list_head_first#prev. == entry ) |
| 104 | head->prevcxx . . $ list_head_first#prev. = prev_entry; |
| 105 | |
| 106 | __list_delcxx . . $ __list_del(6c3f7387ec573de3).( prev_entry, entry->nextcxx . . $ list_head#next. ); |
| 107 | |
| 108 | entry->nextcxx . . $ list_head#next. = (void *) 0; |
| 109 | |
| 110 | } |
| 111 | |
| 112 | |
| 113 | |
| 114 | /** |
| 115 | * list_empty - tests whether a list is empty |
| 116 | * @head: the list to test. |
| 117 | */ |
| 118 | int list_emptycxx . . $ list_empty(563a4e9834c4c63d).( struct list_head_firstcxx . . $ list_head_first# *head ) { |
| 119 | |
| 120 | return head->nextcxx . . $ list_head_first#next. == (struct list_headcxx . . $ list_head# *)head; |
| 121 | |
| 122 | } |
| 123 |