path-util: introduce path_make_relative_parent()
This commit is contained in:
@@ -193,6 +193,24 @@ int path_make_relative(const char *from, const char *to, char **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int path_make_relative_parent(const char *from_child, const char *to, char **ret) {
|
||||
_cleanup_free_ char *from = NULL;
|
||||
int r;
|
||||
|
||||
assert(from_child);
|
||||
assert(to);
|
||||
assert(ret);
|
||||
|
||||
/* Similar to path_make_relative(), but provides the relative path from the parent directory of
|
||||
* 'from_child'. This may be useful when creating relative symlink. */
|
||||
|
||||
r = path_extract_directory(from_child, &from);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return path_make_relative(from, to, ret);
|
||||
}
|
||||
|
||||
char* path_startswith_strv(const char *p, char **set) {
|
||||
STRV_FOREACH(s, set) {
|
||||
char *t;
|
||||
|
||||
@@ -61,6 +61,7 @@ char* path_make_absolute(const char *p, const char *prefix);
|
||||
int safe_getcwd(char **ret);
|
||||
int path_make_absolute_cwd(const char *p, char **ret);
|
||||
int path_make_relative(const char *from, const char *to, char **ret);
|
||||
int path_make_relative_parent(const char *from_child, const char *to, char **ret);
|
||||
char *path_startswith_full(const char *path, const char *prefix, bool accept_dot_dot) _pure_;
|
||||
static inline char* path_startswith(const char *path, const char *prefix) {
|
||||
return path_startswith_full(path, prefix, true);
|
||||
|
||||
Reference in New Issue
Block a user