mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-08 20:58:20 +03:00
path-util: Add path_make_relative_cwd()
This commit is contained in:
parent
e624d4cf07
commit
15b4b4ed06
@ -221,6 +221,33 @@ int path_make_relative_parent(const char *from_child, const char *to, char **ret
|
||||
return path_make_relative(from, to, ret);
|
||||
}
|
||||
|
||||
int path_make_relative_cwd(const char *p, char **ret) {
|
||||
char *c;
|
||||
int r;
|
||||
|
||||
assert(p);
|
||||
assert(ret);
|
||||
|
||||
if (path_is_absolute(p)) {
|
||||
_cleanup_free_ char *cwd = NULL;
|
||||
|
||||
r = safe_getcwd(&cwd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = path_make_relative(cwd, p, &c);
|
||||
if (r < 0)
|
||||
return r;
|
||||
} else {
|
||||
c = strdup(p);
|
||||
if (!c)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
*ret = TAKE_PTR(c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* path_startswith_strv(const char *p, char **set) {
|
||||
STRV_FOREACH(s, set) {
|
||||
char *t;
|
||||
|
@ -62,6 +62,7 @@ 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);
|
||||
int path_make_relative_cwd(const char *from, 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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user