From: Christian Brauner Date: Tue, 26 Jan 2021 14:25:22 +0000 (+0100) Subject: string_utils: add must_make_path_relative() X-Git-Tag: lxc-5.0.0~317^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9cde8a8ab43195a6ce9374bb893efdd392ba6ef3;p=thirdparty%2Flxc.git string_utils: add must_make_path_relative() Stolen without shame from my previous implementation in LXCFS. Cc: stable-4.0 Signed-off-by: Christian Brauner --- diff --git a/src/lxc/string_utils.h b/src/lxc/string_utils.h index a3a00c211..d358b4954 100644 --- a/src/lxc/string_utils.h +++ b/src/lxc/string_utils.h @@ -87,6 +87,16 @@ __hidden __attribute__((sentinel)) extern char *must_concat(size_t *len, const c __hidden __attribute__((sentinel)) extern char *must_make_path(const char *first, ...); __hidden __attribute__((sentinel)) extern char *must_append_path(char *first, ...); +#define must_make_path_relative(__first__, ...) \ + ({ \ + char *__ptr__; \ + if (*__first__ == '/') \ + __ptr__ = must_make_path(".", __first__, __VA_ARGS__); \ + else \ + __ptr__ = must_make_path(__first__, __VA_ARGS__); \ + __ptr__; \ + }) + /* Return copy of string @entry. Do not fail. */ __hidden extern char *must_copy_string(const char *entry);