]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/nulstr-util.h
journald: enable persistent FD Store to fix logging during soft-reboot
[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
08af3cc5 4#include <errno.h>
7f0f5405 5#include <macro.h>
d8b4d14d
LP
6#include <stdbool.h>
7#include <string.h>
8
96c648fe
QD
9#include "set.h"
10
d8b4d14d 11#define NULSTR_FOREACH(i, l) \
12e2b70f 12 for (typeof(*(l)) *(i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)
d8b4d14d
LP
13
14#define NULSTR_FOREACH_PAIR(i, j, l) \
12e2b70f 15 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 16
533f11c5 17const char* nulstr_get(const char *nulstr, const char *needle);
533f11c5
AF
18static inline bool nulstr_contains(const char *nulstr, const char *needle) {
19 return nulstr_get(nulstr, needle);
20}
08af3cc5 21
a4f66f90
YW
22char** strv_parse_nulstr_full(const char *s, size_t l, bool drop_trailing_nuls);
23static inline char** strv_parse_nulstr(const char *s, size_t l) {
24 return strv_parse_nulstr_full(s, l, false);
25}
08af3cc5 26char** strv_split_nulstr(const char *s);
7f0f5405 27static inline int strv_from_nulstr(char ***ret, const char *nulstr) {
08af3cc5
LP
28 char **t;
29
7f0f5405
LP
30 assert(ret);
31
08af3cc5
LP
32 t = strv_split_nulstr(nulstr);
33 if (!t)
34 return -ENOMEM;
7f0f5405
LP
35
36 *ret = t;
08af3cc5
LP
37 return 0;
38}
51e01491
MY
39
40int strv_make_nulstr(char * const *l, char **p, size_t *n);
41int set_make_nulstr(Set *s, char **ret, size_t *ret_size);