]> git.sur5r.net Git - i3/i3/blob - i3bar/include/util.h
Migrate to queue.h
[i3/i3] / i3bar / include / util.h
1 #ifndef UTIL_H_
2 #define UTIL_H_
3
4 #include "queue.h"
5
6 /* Securely free p */
7 #define FREE(p) do { \
8         if (p != NULL) { \
9                 free(p); \
10                 p = NULL; \
11         } \
12 } while (0)
13
14 /* Securely fee single-linked list */
15 #define FREE_SLIST(l, type) do { \
16         type *walk = SLIST_FIRST(l); \
17         while (!SLIST_EMPTY(l)) { \
18                 SLIST_REMOVE_HEAD(l, slist); \
19                 FREE(walk); \
20                 walk = SLIST_FIRST(l); \
21         } \
22 } while (0)
23
24 #endif
25
26 /* Securely fee tail-queues */
27 #define FREE_TAILQ(l, type) do { \
28         type *walk = TAILQ_FIRST(l); \
29         while (!TAILQ_EMPTY(l)) { \
30                 TAILQ_REMOVE(l, TAILQ_FIRST(l), tailq); \
31                 FREE(walk); \
32                 walk = TAILQ_FIRST(l); \
33         } \
34 } while (0)