]>
git.ipfire.org Git - thirdparty/kmod.git/blob - libkmod/libkmod-list.c
2 * libkmod - interface to kernel module operations
4 * Copyright (C) 2011 ProFUSION embedded systems
5 * Copyright (C) 2011 Lucas De Marchi <lucas.de.marchi@gmail.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation version 2.1.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "libkmod-private.h"
25 #include "libkmod-util.h"
27 static inline struct list_node
*list_node_init(struct list_node
*node
)
35 static inline struct list_node
*list_node_next(struct list_node
*node
)
43 static inline struct list_node
*list_node_prev(struct list_node
*node
)
51 static inline void list_node_append(struct list_node
*list
,
52 struct list_node
*node
)
59 node
->prev
= list
->prev
;
60 list
->prev
->next
= node
;
65 static inline struct list_node
*list_node_remove(struct list_node
*node
)
67 if (node
->prev
== node
|| node
->next
== node
)
70 node
->prev
->next
= node
->next
;
71 node
->next
->prev
= node
->prev
;
76 struct kmod_list
*kmod_list_append(struct kmod_list
*list
, void *data
)
78 struct kmod_list
*new;
80 new = malloc(sizeof(*new));
85 list_node_append(list
? &list
->node
: NULL
, &new->node
);
87 return list
? list
: new;
90 struct kmod_list
*kmod_list_prepend(struct kmod_list
*list
, void *data
)
92 struct kmod_list
*new;
94 new = malloc(sizeof(*new));
99 list_node_append(list
? &list
->node
: NULL
, &new->node
);
104 struct kmod_list
*kmod_list_remove(struct kmod_list
*list
)
106 struct list_node
*node
;
111 node
= list_node_remove(&list
->node
);
117 return container_of(node
, struct kmod_list
, node
);
120 struct kmod_list
*kmod_list_remove_data(struct kmod_list
*list
,
123 struct kmod_list
*itr
;
124 struct list_node
*node
;
126 for (itr
= list
; itr
!= NULL
; itr
= kmod_list_next(list
, itr
)) {
127 if (itr
->data
== data
)
134 node
= list_node_remove(&itr
->node
);
140 return container_of(node
, struct kmod_list
, node
);
143 KMOD_EXPORT
struct kmod_list
*kmod_list_next(struct kmod_list
*list
,
144 struct kmod_list
*curr
)
146 if (list
== NULL
|| curr
== NULL
)
149 if (curr
->node
.next
== &list
->node
)
152 return container_of(curr
->node
.next
, struct kmod_list
, node
);