Skip to content

Commit

Permalink
str_list: Add a doubly linked string list structure
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuchircu committed Dec 20, 2017
1 parent 073a53a commit 0d57d6e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions str_list.h
Expand Up @@ -25,12 +25,18 @@

#include "str.h"
#include "lib/osips_malloc.h"
#include "lib/list.h"

struct str_list {
str s;
struct str_list *next;
};

struct str_dlist {
str s;
struct list_head list;
};

static inline void _free_str_list(struct str_list *list,
osips_free_t free_item, osips_free_t free_str)
{
Expand All @@ -54,4 +60,26 @@ static inline void _free_str_list(struct str_list *list,
#define free_shm_str_list(list) \
_free_str_list(list, osips_shm_free, osips_shm_free)

static inline void _free_str_dlist(struct list_head *dlist,
osips_free_t free_item, osips_free_t free_str)
{
struct list_head *_, *__;
struct str_dlist *item;

list_for_each_safe(_, __, dlist) {
item = list_entry(_, struct str_dlist, list);
if (free_str)
free_str(item->s.s);

if (free_item)
free_item(item);
}
}

#define free_pkg_str_dlist(list) \
_free_str_dlist(list, osips_pkg_free, osips_pkg_free)

#define free_shm_str_dlist(list) \
_free_str_dlist(list, osips_shm_free, osips_shm_free)

#endif /* __STR_LIST__ */

0 comments on commit 0d57d6e

Please sign in to comment.