mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-26 23:37:22 +00:00
utils: Add lxc_append_paths to join two paths.
Signed-off-by: Christian Seiler <christian@iwakd.de> Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
parent
4bee03bc9d
commit
24b514827d
@ -658,6 +658,25 @@ char **lxc_normalize_path(const char *path)
|
|||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *lxc_append_paths(const char *first, const char *second)
|
||||||
|
{
|
||||||
|
size_t len = strlen(first) + strlen(second) + 1;
|
||||||
|
const char *pattern = "%s%s";
|
||||||
|
char *result = NULL;
|
||||||
|
|
||||||
|
if (second[0] != '/') {
|
||||||
|
len += 1;
|
||||||
|
pattern = "%s/%s";
|
||||||
|
}
|
||||||
|
|
||||||
|
result = calloc(1, len);
|
||||||
|
if (!result)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
snprintf(result, len, pattern, first, second);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool lxc_string_in_list(const char *needle, const char *haystack, char _sep)
|
bool lxc_string_in_list(const char *needle, const char *haystack, char _sep)
|
||||||
{
|
{
|
||||||
char *token, *str, *saveptr = NULL;
|
char *token, *str, *saveptr = NULL;
|
||||||
|
@ -219,6 +219,7 @@ extern char *lxc_string_join(const char *sep, const char **parts, bool use_as_pr
|
|||||||
* foo//bar -> { foo, bar, NULL }
|
* foo//bar -> { foo, bar, NULL }
|
||||||
*/
|
*/
|
||||||
extern char **lxc_normalize_path(const char *path);
|
extern char **lxc_normalize_path(const char *path);
|
||||||
|
extern char *lxc_append_paths(const char *first, const char *second);
|
||||||
/* Note: the following two functions use strtok(), so they will never
|
/* Note: the following two functions use strtok(), so they will never
|
||||||
* consider an empty element, even if two delimiters are next to
|
* consider an empty element, even if two delimiters are next to
|
||||||
* each other.
|
* each other.
|
||||||
|
Loading…
Reference in New Issue
Block a user