]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
strings: Add function to merge multiple strings into an array
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 Jan 2025 15:23:05 +0000 (15:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 Jan 2025 15:23:05 +0000 (15:23 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/string.c
src/pakfire/string.h

index 74992a9acd9fc69fdeb7b4335f0963fa7757815d..d1ca24c0203839fc90c03e9927083b3b35700485 100644 (file)
@@ -471,6 +471,25 @@ int pakfire_strings_appendf(char*** array, const char* format, ...) {
        return r;
 }
 
+/*
+       Copies all strings into the array
+*/
+int pakfire_strings_appendm(char*** array, const char** strings) {
+       int r = 0;
+
+       // Check inputs
+       if (!strings)
+               return -EINVAL;
+
+       for (const char** s = strings; *s; s++) {
+               r = pakfire_strings_append(array, *s);
+               if (r < 0)
+                       return r;
+       }
+
+       return r;
+}
+
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
 int __pakfire_format_size(char* dst, size_t length, double value) {
index 2fbccd14594e23daa48bc475b955daf3649905bb..6e3cd6526cb1563f867e78a7b07190cf4c8ddae3 100644 (file)
@@ -98,6 +98,7 @@ void pakfire_strings_free(char** array);
 int pakfire_strings_append(char*** array, const char* s);
 int pakfire_strings_appendf(char*** array, const char* format, ...)
        __attribute__((format(printf, 2, 3)));
+int pakfire_strings_appendm(char*** array, const char** strings);
 
 #define TIME_STRING_MAX 32