lxc_append_string() appends strings without separator. This is mostly useful
for reading in whole files line-by-line.
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
fclose(f);
return bret;
}
+
+static int lxc_append_null_to_list(void ***list)
+{
+ int newentry = 0;
+ void **tmp;
+
+ if (*list)
+ for (; (*list)[newentry]; newentry++) {
+ ;
+ }
+
+ tmp = realloc(*list, (newentry + 2) * sizeof(void **));
+ if (!tmp)
+ return -1;
+
+ *list = tmp;
+ (*list)[newentry + 1] = NULL;
+
+ return newentry;
+}
+
+int lxc_append_string(char ***list, char *entry)
+{
+ int newentry = lxc_append_null_to_list((void ***)list);
+ char *copy;
+
+ copy = strdup(entry);
+ if (!copy)
+ return -1;
+
+ (*list)[newentry] = copy;
+
+ return 0;
+}
extern bool lxc_string_in_list(const char *needle, const char *haystack, char sep);
extern char **lxc_string_split(const char *string, char sep);
extern char **lxc_string_split_and_trim(const char *string, char sep);
+/* Append string to NULL-terminated string array. */
+extern int lxc_append_string(char ***list, char *entry);
/* some simple array manipulation utilities */
typedef void (*lxc_free_fn)(void *);