1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3 Date: Wed, 18 Jul 2018 12:43:37 +0200
4 Subject: [PATCH] utils: add must_concat helper
6 Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
7 (cherry picked from commit eb5c2e6aeef233c4f3349d182e5c25315cca8de8)
9 src/lxc/utils.c | 24 ++++++++++++++++++++++++
11 2 files changed, 25 insertions(+)
13 diff --git a/src/lxc/utils.c b/src/lxc/utils.c
14 index dd6cdc91..9771b900 100644
17 @@ -2426,6 +2426,30 @@ int run_command(char *buf, size_t buf_size, int (*child_fn)(void *), void *args)
21 +char *must_concat(const char *first, ...)
25 + size_t cur_len, it_len;
27 + dest = must_copy_string(first);
28 + cur_len = it_len = strlen(first);
30 + va_start(args, first);
31 + while ((cur = va_arg(args, char *)) != NULL) {
32 + it_len = strlen(cur);
34 + dest = must_realloc(dest, cur_len + it_len + 1);
36 + (void)memcpy(dest + cur_len, cur, it_len);
45 char *must_make_path(const char *first, ...)
48 diff --git a/src/lxc/utils.h b/src/lxc/utils.h
49 index 295e7862..ed486853 100644
52 @@ -567,6 +567,7 @@ extern int run_command(char *buf, size_t buf_size, int (*child_fn)(void *),
53 /* Concatenate all passed-in strings into one path. Do not fail. If any piece
54 * is not prefixed with '/', add a '/'.
56 +__attribute__((sentinel)) extern char *must_concat(const char *first, ...);
57 __attribute__((sentinel)) extern char *must_make_path(const char *first, ...);
58 __attribute__((sentinel)) extern char *must_append_path(char *first, ...);