]> git.ipfire.org Git - thirdparty/util-linux.git/blob - include/strv.h
Merge branch 'lsclocks/rtc' of https://github.com/t-8ch/util-linux
[thirdparty/util-linux.git] / include / strv.h
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-or-later
3 */
4 #ifndef UTIL_LINUX_STRV
5 #define UTIL_LINUX_STRV
6
7 #include <stdarg.h>
8
9 #include "c.h"
10
11 char **strv_free(char **l);
12 void strv_clear(char **l);
13 char **strv_copy(char * const *l);
14 unsigned strv_length(char * const *l);
15
16 int strv_extend_strv(char ***a, char **b);
17 int strv_extend_strv_concat(char ***a, char **b, const char *suffix);
18 int strv_extend(char ***l, const char *value);
19
20 int strv_extendv(char ***l, const char *format, va_list ap)
21 __attribute__ ((__format__ (__printf__, 2, 0)));
22 int strv_extendf(char ***l, const char *format, ...)
23 __attribute__ ((__format__ (__printf__, 2, 3)));
24
25 int strv_push(char ***l, char *value);
26 int strv_push_prepend(char ***l, char *value);
27 int strv_consume(char ***l, char *value);
28 int strv_consume_prepend(char ***l, char *value);
29
30 char **strv_remove(char **l, const char *s);
31
32 char **strv_new(const char *x, ...);
33 char **strv_new_ap(const char *x, va_list ap);
34
35 static inline const char* STRV_IFNOTNULL(const char *x) {
36 return x ? x : (const char *) -1;
37 }
38
39 static inline int strv_isempty(char * const *l) {
40 return !l || !*l;
41 }
42
43 char **strv_split(const char *s, const char *separator);
44 char *strv_join(char **l, const char *separator);
45
46 #define STRV_FOREACH(s, l) \
47 for ((s) = (l); (s) && *(s); (s)++)
48
49 #define STRV_FOREACH_BACKWARDS(s, l) \
50 STRV_FOREACH(s, l) \
51 ; \
52 for ((s)--; (l) && ((s) >= (l)); (s)--)
53
54
55 #define STRV_MAKE_EMPTY ((char*[1]) { NULL })
56
57 char **strv_reverse(char **l);
58
59 #endif /* UTIL_LINUX_STRV */
60
61