]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
strings: Add a function to dump a string array
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Jan 2025 15:12:23 +0000 (15:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Jan 2025 15:12:23 +0000 (15:12 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/string.c
src/pakfire/string.h

index d1ca24c0203839fc90c03e9927083b3b35700485..e44b7b3aa66654a0a90386a181a53a15d3e527e5 100644 (file)
@@ -490,6 +490,35 @@ int pakfire_strings_appendm(char*** array, const char** strings) {
        return r;
 }
 
+/*
+       This function dumps the string array to the console. This is useful for debugging only.
+*/
+int pakfire_strings_dump(char** array) {
+       int r;
+
+       // Check inputs
+       if (!array)
+               return -EINVAL;
+
+       // Determine the length of the array
+       size_t length = pakfire_strings_length(array);
+
+       // If the array is empty, we return a message
+       if (!length) {
+               printf("Empty string array\n");
+               return 0;
+       }
+
+       // Dump the array
+       for (unsigned int i = 0; i < length; i++) {
+               r = printf("array[%u] : %s\n", i, array[i]);
+               if (r < 0)
+                       return r;
+       }
+
+       return 0;
+}
+
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
 int __pakfire_format_size(char* dst, size_t length, double value) {
index 6e3cd6526cb1563f867e78a7b07190cf4c8ddae3..91dd1b618e4ce4737f78380197e725ba23b6b3e1 100644 (file)
@@ -100,6 +100,8 @@ int pakfire_strings_appendf(char*** array, const char* format, ...)
        __attribute__((format(printf, 2, 3)));
 int pakfire_strings_appendm(char*** array, const char** strings);
 
+int pakfire_strings_dump(char** array);
+
 #define TIME_STRING_MAX 32
 
 #define pakfire_format_size(dst, value) \