summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLuca Boccassi <bluca@debian.org>2023-06-01 20:32:29 +0200
committerLuca Boccassi <bluca@debian.org>2023-06-09 01:49:19 +0200
commit1d6f1e2fa1820e66ce8fea44cbefbbf3389d1cdf (patch)
tree02340a232c6129e3ab9fb7fa993d90caff447e96 /src
parenttest-execute: add unit tests for *DirectorySymlink= (diff)
downloadsystemd-1d6f1e2fa1820e66ce8fea44cbefbbf3389d1cdf.tar.xz
systemd-1d6f1e2fa1820e66ce8fea44cbefbbf3389d1cdf.zip
serialize: add deserialize_strv helper
Diffstat (limited to 'src')
-rw-r--r--src/shared/serialize.c14
-rw-r--r--src/shared/serialize.h1
-rw-r--r--src/test/test-serialize.c5
3 files changed, 16 insertions, 4 deletions
diff --git a/src/shared/serialize.c b/src/shared/serialize.c
index 9d1a21360f..5396062a8b 100644
--- a/src/shared/serialize.c
+++ b/src/shared/serialize.c
@@ -131,6 +131,20 @@ int serialize_strv(FILE *f, const char *key, char **l) {
return ret;
}
+int deserialize_strv(char ***l, const char *value) {
+ ssize_t unescaped_len;
+ char *unescaped;
+
+ assert(l);
+ assert(value);
+
+ unescaped_len = cunescape(value, 0, &unescaped);
+ if (unescaped_len < 0)
+ return unescaped_len;
+
+ return strv_consume(l, unescaped);
+}
+
int deserialize_usec(const char *value, usec_t *ret) {
int r;
diff --git a/src/shared/serialize.h b/src/shared/serialize.h
index 6d4f1ef418..8fdc6dc304 100644
--- a/src/shared/serialize.h
+++ b/src/shared/serialize.h
@@ -23,5 +23,6 @@ static inline int serialize_bool(FILE *f, const char *key, bool b) {
int deserialize_usec(const char *value, usec_t *timestamp);
int deserialize_dual_timestamp(const char *value, dual_timestamp *t);
int deserialize_environment(const char *value, char ***environment);
+int deserialize_strv(char ***l, const char *value);
int open_serialization_fd(const char *ident);
diff --git a/src/test/test-serialize.c b/src/test/test-serialize.c
index bcf2e843b0..a297e9515e 100644
--- a/src/test/test-serialize.c
+++ b/src/test/test-serialize.c
@@ -124,10 +124,7 @@ TEST(serialize_strv) {
const char *t = startswith(line, "strv3=");
assert_se(t);
-
- char *un;
- assert_se(cunescape(t, 0, &un) >= 0);
- assert_se(strv_consume(&strv2, un) >= 0);
+ assert_se(deserialize_strv(&strv2, t) >= 0);
}
assert_se(strv_equal(strv, strv2));