From 82443be506be8b421fdd2771ad3e9a7d3014cb7b Mon Sep 17 00:00:00 2001 From: williamvds Date: Wed, 21 Oct 2020 17:14:37 +0100 Subject: [PATCH] Add strv_prepend Inserts a copy of the value at the head of the list. --- src/basic/strv.c | 13 +++++++++++++ src/basic/strv.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/basic/strv.c b/src/basic/strv.c index b2b6de388a..c5e6dd5f21 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -537,6 +537,19 @@ int strv_consume_prepend(char ***l, char *value) { return r; } +int strv_prepend(char ***l, const char *value) { + char *v; + + if (!value) + return 0; + + v = strdup(value); + if (!v) + return -ENOMEM; + + return strv_consume_prepend(l, v); +} + int strv_extend(char ***l, const char *value) { char *v; diff --git a/src/basic/strv.h b/src/basic/strv.h index 919fabf75a..f2aa6c239b 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -34,6 +34,7 @@ size_t strv_length(char * const *l) _pure_; int strv_extend_strv(char ***a, char * const *b, bool filter_duplicates); int strv_extend_strv_concat(char ***a, char * const *b, const char *suffix); +int strv_prepend(char ***l, const char *value); int strv_extend(char ***l, const char *value); int strv_extendf(char ***l, const char *format, ...) _printf_(2,0); int strv_extend_front(char ***l, const char *value);