mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-06-12 10:31:20 +00:00
utils: add lxc_append_string()
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>
This commit is contained in:
parent
5e8b774630
commit
000dfda7f3
@ -1930,3 +1930,37 @@ out:
|
||||
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;
|
||||
}
|
||||
|
@ -258,6 +258,8 @@ extern char *lxc_append_paths(const char *first, const char *second);
|
||||
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 *);
|
||||
|
Loading…
Reference in New Issue
Block a user