Merge pull request #27199 from yuwata/find-esp
path-util: introduce path_prefix_root_cwd(), and use it in find_esp() and friends
This commit is contained in:
@@ -100,6 +100,34 @@ int path_make_absolute_cwd(const char *p, char **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int path_prefix_root_cwd(const char *p, const char *root, char **ret) {
|
||||
_cleanup_free_ char *root_abs = NULL;
|
||||
char *c;
|
||||
int r;
|
||||
|
||||
assert(p);
|
||||
assert(ret);
|
||||
|
||||
/* Unlike path_make_absolute(), this always prefixes root path if specified.
|
||||
* The root path is always simplified, but the provided path will not.
|
||||
* This is useful for prefixing the result of chaseat(). */
|
||||
|
||||
if (empty_or_root(root))
|
||||
return path_make_absolute_cwd(p, ret);
|
||||
|
||||
r = path_make_absolute_cwd(root, &root_abs);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
path_simplify(root_abs);
|
||||
c = path_join(root_abs, p);
|
||||
if (!c)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int path_make_relative(const char *from, const char *to, char **ret) {
|
||||
_cleanup_free_ char *result = NULL;
|
||||
unsigned n_parents;
|
||||
|
||||
@@ -60,6 +60,7 @@ int path_split_and_make_absolute(const char *p, char ***ret);
|
||||
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_prefix_root_cwd(const char *p, const char *root, 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_;
|
||||
|
||||
Reference in New Issue
Block a user