summaryrefslogtreecommitdiffstats
path: root/include/stringlist.h
blob: dbf159da91b64805d52ef2a800c4b1a7e6013962 (plain) (blame)
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
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef __STRINGLIST_H
#define __STRINGLIST_H

#include <linux/list.h>

struct string_list {
	struct list_head list;
	char *str;
};

int string_list_add(struct string_list *sl, const char *str);
int string_list_add_asprintf(struct string_list *sl, const char *fmt, ...);
int string_list_add_sorted(struct string_list *sl, const char *str);
int string_list_add_sort_uniq(struct string_list *sl, const char *str);
int string_list_contains(struct string_list *sl, const char *str);
void string_list_print_by_column(struct string_list *sl);

static inline void string_list_init(struct string_list *sl)
{
	INIT_LIST_HEAD(&sl->list);
}

static inline void string_list_free(struct string_list *sl)
{
	struct string_list *entry, *safe;

	list_for_each_entry_safe(entry, safe, &sl->list, list) {
		free(entry->str);
		free(entry);
	}
}

#define string_list_for_each_entry(entry, sl) \
	list_for_each_entry(entry, &(sl)->list, list)

#endif /* __STRINGLIST_H */