diff options
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/fs-util.c | 20 | ||||
-rw-r--r-- | src/basic/fs-util.h | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index cddd4232fc..2b6189ad90 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -233,6 +233,26 @@ int readlink_and_canonicalize(const char *p, char **r) { return 0; } +int readlink_and_make_absolute_root(const char *root, const char *path, char **ret) { + _cleanup_free_ char *target = NULL, *t = NULL; + const char *full; + int r; + + full = prefix_roota(root, path); + r = readlink_malloc(full, &target); + if (r < 0) + return r; + + t = file_in_same_dir(path, target); + if (!t) + return -ENOMEM; + + *ret = t; + t = NULL; + + return 0; +} + int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid) { assert(path); diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h index b94873e65b..902c7e295b 100644 --- a/src/basic/fs-util.h +++ b/src/basic/fs-util.h @@ -40,6 +40,7 @@ int readlink_malloc(const char *p, char **r); int readlink_value(const char *p, char **ret); int readlink_and_make_absolute(const char *p, char **r); int readlink_and_canonicalize(const char *p, char **r); +int readlink_and_make_absolute_root(const char *root, const char *path, char **ret); int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid); int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid); |