libliftoff/include/list.h
Simon Ser caac9bc87f
Rename library to liftoff
Let's make these planes useful!
2019-09-12 11:40:21 +03:00

34 lines
1.1 KiB
C

#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);
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