summaryrefslogtreecommitdiffstats
path: root/src/basic
diff options
context:
space:
mode:
authorLuca Boccassi <bluca@debian.org>2023-11-03 17:59:32 +0100
committerLuca Boccassi <bluca@debian.org>2023-11-03 17:59:58 +0100
commita39cba252ede11013b600dd858c9459bb707d663 (patch)
tree9e1f538267192f096981a2b3b1aa2b93fb568388 /src/basic
parentNEWS: add entry for vmspawn (diff)
downloadsystemd-a39cba252ede11013b600dd858c9459bb707d663.tar.xz
systemd-a39cba252ede11013b600dd858c9459bb707d663.zip
strv: add strv_free_many() to be used with CLEANUP_ARRAY()
Diffstat (limited to '')
-rw-r--r--src/basic/strv.c9
-rw-r--r--src/basic/strv.h2
2 files changed, 11 insertions, 0 deletions
diff --git a/src/basic/strv.c b/src/basic/strv.c
index 37c8f553eb..c2109d35bc 100644
--- a/src/basic/strv.c
+++ b/src/basic/strv.c
@@ -88,6 +88,15 @@ char** strv_free_erase(char **l) {
return mfree(l);
}
+void strv_free_many(char ***strvs, size_t n) {
+ assert(strvs || n == 0);
+
+ FOREACH_ARRAY (i, strvs, n)
+ strv_free(*i);
+
+ free(strvs);
+}
+
char** strv_copy_n(char * const *l, size_t m) {
_cleanup_strv_free_ char **result = NULL;
char **k;
diff --git a/src/basic/strv.h b/src/basic/strv.h
index 544d46a3f8..fec2616733 100644
--- a/src/basic/strv.h
+++ b/src/basic/strv.h
@@ -32,6 +32,8 @@ char** strv_free_erase(char **l);
DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free_erase);
#define _cleanup_strv_free_erase_ _cleanup_(strv_free_erasep)
+void strv_free_many(char ***strvs, size_t n);
+
char** strv_copy_n(char * const *l, size_t n);
static inline char** strv_copy(char * const *l) {
return strv_copy_n(l, SIZE_MAX);