Migrate to queue.h

This commit is contained in:
Axel Wagner
2010-07-30 03:11:54 +02:00
parent 654b51fef1
commit 43c057f19a
8 changed files with 96 additions and 98 deletions

View File

@ -1,6 +1,8 @@
#ifndef UTIL_H_
#define UTIL_H_
#include "queue.h"
/* Securely free p */
#define FREE(p) do { \
if (p != NULL) { \
@ -10,13 +12,23 @@
} while (0)
/* Securely fee single-linked list */
#define FREE_LIST(l, type) do { \
type* FREE_LIST_TMP; \
while (l != NULL) { \
FREE_LIST_TMP = l; \
free(l); \
l = l->next; \
#define FREE_SLIST(l, type) do { \
type *walk = SLIST_FIRST(l); \
while (!SLIST_EMPTY(l)) { \
SLIST_REMOVE_HEAD(l, slist); \
FREE(walk); \
walk = SLIST_FIRST(l); \
} \
} while (0)
#endif
/* Securely fee tail-queues */
#define FREE_TAILQ(l, type) do { \
type *walk = TAILQ_FIRST(l); \
while (!TAILQ_EMPTY(l)) { \
TAILQ_REMOVE(l, TAILQ_FIRST(l), tailq); \
FREE(walk); \
walk = TAILQ_FIRST(l); \
} \
} while (0)