]> git.proxmox.com Git - lxc.git/blob - debian/patches/extra/0008-utils-add-must_concat-helper.patch
bump version to 3.0.1+pve1-1
[lxc.git] / debian / patches / extra / 0008-utils-add-must_concat-helper.patch
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
5
6 Signed-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
13 diff --git a/src/lxc/utils.c b/src/lxc/utils.c
14 index 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;
48 diff --git a/src/lxc/utils.h b/src/lxc/utils.h
49 index 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 --
61 2.11.0
62