-
Notifications
You must be signed in to change notification settings - Fork 8
/
list.h
45 lines (33 loc) · 916 Bytes
/
list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef LIST_HDR
#define LIST_HDR
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct link_s link_t;
typedef struct list_s list_t;
struct link_s {
link_t *prev;
link_t *next;
};
struct list_s {
link_t *head;
link_t *tail;
};
void list_init(list_t *list);
void list_push_front(list_t *list, link_t *link);
void list_push_back(list_t *list, link_t *link);
void list_insert_before(list_t *list, link_t *before, link_t *link);
void list_insert_after(list_t *list, link_t *after, link_t *link);
link_t *list_pop_front(list_t *list);
link_t *list_pop_back(list_t *list);
link_t *list_head(const list_t *list);
link_t *list_tail(const list_t *list);
link_t *list_next(const link_t *link);
link_t *list_prev(const link_t *link);
#define list_ref(ELEMENT, TYPE, MEMBER) \
((TYPE *)((unsigned char *)(ELEMENT) - offsetof(TYPE, MEMBER)))
#ifdef __cplusplus
}
#endif
#endif