]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Add strv_prepend
authorwilliamvds <william@williamvds.me>
Wed, 21 Oct 2020 16:14:37 +0000 (17:14 +0100)
committerwilliamvds <william@williamvds.me>
Wed, 21 Oct 2020 16:14:37 +0000 (17:14 +0100)
Inserts a copy of the value at the head of the list.

src/basic/strv.c
src/basic/strv.h

index b2b6de388a9bef9bbcae309b7305da7b1ef55692..c5e6dd5f2182f188578d96c208127e6510cb26cd 100644 (file)
@@ -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;
 
index 919fabf75aa9bac67a3d299bb40f894669bfe4a1..f2aa6c239bdca4fd4be27d756d4cdb92dcf8599d 100644 (file)
@@ -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);