]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/nulstr-util.h
man/systemd-sysext: list ephemeral/ephemeral-import in the list of options
[thirdparty/systemd.git] / src / basic / nulstr-util.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
d8b4d14d
LP
2#pragma once
3
d8b4d14d
LP
4#include <string.h>
5
0c15577a 6#include "forward.h"
96c648fe 7
d8b4d14d 8#define NULSTR_FOREACH(i, l) \
12e2b70f 9 for (typeof(*(l)) *(i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)
d8b4d14d
LP
10
11#define NULSTR_FOREACH_PAIR(i, j, l) \
12e2b70f 12 for (typeof(*(l)) *(i) = (l), *(j) = strchr((i), 0)+1; (i) && *(i); (i) = strchr((j), 0)+1, (j) = *(i) ? strchr((i), 0)+1 : (i))
d8b4d14d 13
533f11c5 14const char* nulstr_get(const char *nulstr, const char *needle);
533f11c5
AF
15static inline bool nulstr_contains(const char *nulstr, const char *needle) {
16 return nulstr_get(nulstr, needle);
17}
08af3cc5 18
a4f66f90
YW
19char** strv_parse_nulstr_full(const char *s, size_t l, bool drop_trailing_nuls);
20static inline char** strv_parse_nulstr(const char *s, size_t l) {
21 return strv_parse_nulstr_full(s, l, false);
22}
08af3cc5 23char** strv_split_nulstr(const char *s);
7f0f5405 24static inline int strv_from_nulstr(char ***ret, const char *nulstr) {
08af3cc5
LP
25 char **t;
26
7f0f5405
LP
27 assert(ret);
28
08af3cc5
LP
29 t = strv_split_nulstr(nulstr);
30 if (!t)
31 return -ENOMEM;
7f0f5405
LP
32
33 *ret = t;
08af3cc5
LP
34 return 0;
35}
51e01491
MY
36
37int strv_make_nulstr(char * const *l, char **p, size_t *n);
38int set_make_nulstr(Set *s, char **ret, size_t *ret_size);