Skip to content

Commit

Permalink
string_utils: add must_make_path_relative()
Browse files Browse the repository at this point in the history
Stolen without shame from my previous implementation in LXCFS.

Cc: stable-4.0
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Jan 26, 2021
1 parent d23cb29 commit 9cde8a8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lxc/string_utils.h
Expand Up @@ -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);

Expand Down

0 comments on commit 9cde8a8

Please sign in to comment.