blob: 7b9ef32fae849ee11d97743964d51648b31285f9 [file] [log] [blame]
Colin Crossed8a7d82010-04-19 17:05:34 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _INIT_LIST_H_
18#define _INIT_LIST_H_
19
Olivier Baillyb93e5812010-11-17 11:47:23 -080020#include <stddef.h>
21
Colin Crossed8a7d82010-04-19 17:05:34 -070022struct listnode
23{
24 struct listnode *next;
25 struct listnode *prev;
26};
27
28#define node_to_item(node, container, member) \
29 (container *) (((char*) (node)) - offsetof(container, member))
30
31#define list_declare(name) \
32 struct listnode name = { \
33 .next = &name, \
34 .prev = &name, \
35 }
36
37#define list_for_each(node, list) \
38 for (node = (list)->next; node != (list); node = node->next)
39
Colin Cross44b65d02010-04-20 14:32:50 -070040#define list_for_each_reverse(node, list) \
41 for (node = (list)->prev; node != (list); node = node->prev)
42
Colin Crossed8a7d82010-04-19 17:05:34 -070043void list_init(struct listnode *list);
44void list_add_tail(struct listnode *list, struct listnode *item);
45void list_remove(struct listnode *item);
46
47#define list_empty(list) ((list) == (list)->next)
48#define list_head(list) ((list)->next)
49#define list_tail(list) ((list)->prev)
50
51#endif