]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
string_utils: add must_make_path_relative()
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 26 Jan 2021 14:25:22 +0000 (15:25 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 26 Jan 2021 14:29:14 +0000 (15:29 +0100)
Stolen without shame from my previous implementation in LXCFS.

Cc: stable-4.0
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/string_utils.h

index a3a00c211cc2a8a2f482e39e0861a56d46dd21dd..d358b49540dd8b553aef42e88978883b52cdc84e 100644 (file)
@@ -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);