]> git.proxmox.com Git - lxc.git/blame - debian/patches/extra/0008-utils-add-must_concat-helper.patch
bump version to 3.0.1+pve2-1
[lxc.git] / debian / patches / extra / 0008-utils-add-must_concat-helper.patch
CommitLineData
2d8021b3
WB
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3Date: Wed, 18 Jul 2018 12:43:37 +0200
4Subject: [PATCH] utils: add must_concat helper
5
6Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
7(cherry picked from commit eb5c2e6aeef233c4f3349d182e5c25315cca8de8)
8---
9 src/lxc/utils.c | 24 ++++++++++++++++++++++++
10 src/lxc/utils.h | 1 +
11 2 files changed, 25 insertions(+)
12
13diff --git a/src/lxc/utils.c b/src/lxc/utils.c
14index dd6cdc91..9771b900 100644
15--- a/src/lxc/utils.c
16+++ b/src/lxc/utils.c
17@@ -2426,6 +2426,30 @@ int run_command(char *buf, size_t buf_size, int (*child_fn)(void *), void *args)
18 return fret;
19 }
20
21+char *must_concat(const char *first, ...)
22+{
23+ va_list args;
24+ char *cur, *dest;
25+ size_t cur_len, it_len;
26+
27+ dest = must_copy_string(first);
28+ cur_len = it_len = strlen(first);
29+
30+ va_start(args, first);
31+ while ((cur = va_arg(args, char *)) != NULL) {
32+ it_len = strlen(cur);
33+
34+ dest = must_realloc(dest, cur_len + it_len + 1);
35+
36+ (void)memcpy(dest + cur_len, cur, it_len);
37+ cur_len += it_len;
38+ }
39+ va_end(args);
40+
41+ dest[cur_len] = 0;
42+ return dest;
43+}
44+
45 char *must_make_path(const char *first, ...)
46 {
47 va_list args;
48diff --git a/src/lxc/utils.h b/src/lxc/utils.h
49index 295e7862..ed486853 100644
50--- a/src/lxc/utils.h
51+++ b/src/lxc/utils.h
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 '/'.
55 */
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, ...);
59
60--
612.11.0
62