From: williamvds Date: Wed, 21 Oct 2020 16:14:37 +0000 (+0100) Subject: Add strv_prepend X-Git-Tag: v247-rc1~23^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=82443be506be8b421fdd2771ad3e9a7d3014cb7b;p=thirdparty%2Fsystemd.git Add strv_prepend Inserts a copy of the value at the head of the list. --- diff --git a/src/basic/strv.c b/src/basic/strv.c index b2b6de388a9..c5e6dd5f218 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 919fabf75aa..f2aa6c239bd 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);