File: list.h

package info (click to toggle)
libliftoff 0.5.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 352 kB
  • sloc: ansic: 5,432; makefile: 3
file content (46 lines) | stat: -rw-r--r-- 1,230 bytes parent folder | download
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
46
#ifndef LIST_H
#define LIST_H

#include <stdbool.h>
#include <stddef.h>

struct liftoff_list {
	struct liftoff_list *prev;
	struct liftoff_list *next;
};

void
liftoff_list_init(struct liftoff_list *list);

void
liftoff_list_insert(struct liftoff_list *list, struct liftoff_list *elm);

void
liftoff_list_remove(struct liftoff_list *elm);

void
liftoff_list_swap(struct liftoff_list *this, struct liftoff_list *other);

size_t
liftoff_list_length(const struct liftoff_list *list);

bool
liftoff_list_empty(const struct liftoff_list *list);

#define liftoff_container_of(ptr, sample, member)			\
	(__typeof__(sample))((char *)(ptr) -				\
			     offsetof(__typeof__(*sample), member))

#define liftoff_list_for_each(pos, head, member)			\
	for (pos = liftoff_container_of((head)->next, pos, member);	\
	     &pos->member != (head);					\
	     pos = liftoff_container_of(pos->member.next, pos, member))

#define liftoff_list_for_each_safe(pos, tmp, head, member)		\
	for (pos = liftoff_container_of((head)->next, pos, member),	\
	     tmp = liftoff_container_of(pos->member.next, tmp, member);	\
	     &pos->member != (head);					\
	     pos = tmp,							\
	     tmp = liftoff_container_of(pos->member.next, tmp, member))

#endif