summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-11-07 19:19:02 +0100
committerTom Gundersen <teg@jklm.no>2014-11-07 19:46:14 +0100
commit9a67bcf27554ee0688198e4d4eb5e541861bf7cb (patch)
tree8aab119116fc451053cf1bde4d14e1ce960d1ec5 /src/shared/util.c
parentf06863bde5de49a503cb8028e89d4b30790f2cbf (diff)
shared: add readlink_value
Reads the basename of the target of a symlink.
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 3411cea343..f0e0c0dd3d 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -893,6 +893,28 @@ int readlink_malloc(const char *p, char **ret) {
return readlinkat_malloc(AT_FDCWD, p, ret);
}
+int readlink_value(const char *p, char **ret) {
+ _cleanup_free_ char *link = NULL;
+ char *value;
+ int r;
+
+ r = readlink_malloc(p, &link);
+ if (r < 0)
+ return r;
+
+ value = basename(link);
+ if (!value)
+ return -ENOENT;
+
+ value = strdup(value);
+ if (!value)
+ return -ENOMEM;
+
+ *ret = value;
+
+ return 0;
+}
+
int readlink_and_make_absolute(const char *p, char **r) {
_cleanup_free_ char *target = NULL;
char *k;