]> git.sur5r.net Git - i3/i3/blob - i3bar/include/util.h
Add licensing information
[i3/i3] / i3bar / include / util.h
1 /*
2  * i3bar - an xcb-based status- and ws-bar for i3
3  *
4  * © 2010 Axel Wagner and contributors
5  *
6  * See file LICNSE for license information
7  *
8  */
9 #ifndef UTIL_H_
10 #define UTIL_H_
11
12 #include "queue.h"
13
14 /* Securely free p */
15 #define FREE(p) do { \
16     if (p != NULL) { \
17         free(p); \
18         p = NULL; \
19     } \
20 } while (0)
21
22 /* Securely fee single-linked list */
23 #define FREE_SLIST(l, type) do { \
24     type *walk = SLIST_FIRST(l); \
25     while (!SLIST_EMPTY(l)) { \
26         SLIST_REMOVE_HEAD(l, slist); \
27         FREE(walk); \
28         walk = SLIST_FIRST(l); \
29     } \
30 } while (0)
31
32 #endif
33
34 /* Securely fee tail-queues */
35 #define FREE_TAILQ(l, type) do { \
36     type *walk = TAILQ_FIRST(l); \
37     while (!TAILQ_EMPTY(l)) { \
38         TAILQ_REMOVE(l, TAILQ_FIRST(l), tailq); \
39         FREE(walk); \
40         walk = TAILQ_FIRST(l); \
41     } \
42 } while (0)