File: utils.h

package info (click to toggle)
libnl3 3.2.27-2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 5,548 kB
  • ctags: 11,023
  • sloc: ansic: 50,883; sh: 11,550; python: 3,702; makefile: 607; yacc: 476; cpp: 454; lex: 202
file content (41 lines) | stat: -rw-r--r-- 961 bytes parent folder | download | duplicates (4)
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
struct list_head {
	struct list_head *next;
};

#define LIST_HEAD(name) \
	struct list_head name = { &(name) }

static inline int list_empty(const struct list_head *head)
{
	return head->next == head;
}

static inline void list_add(struct list_head *new, struct list_head *head)
{
	new->next = head->next;
	head->next = new;
}

static inline void list_del(struct list_head *entry, struct list_head *prev)
{
	prev->next = entry->next;
	entry->next = entry;
}

#define list_for_each_safe(pos, n, head) \
	for (n = (head), pos = (head)->next; pos != (head); \
	     n = pos, pos = n->next)

#undef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

#define container_of(ptr, type, member) ({			\
	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
	(type *)( (char *)__mptr - offsetof(type,member) );})

#ifdef DEBUG
#define pynl_dbg(fmt, ...) \
	fprintf(stderr, "%s: " fmt, __func__, __VA_ARGS__)
#else
#define pynl_dbg(fmt, ...)
#endif