[systemd-commits] src/shared
Tom Gundersen
tomegun at kemper.freedesktop.org
Fri Nov 7 10:50:41 PST 2014
src/shared/util.c | 22 ++++++++++++++++++++++
src/shared/util.h | 1 +
2 files changed, 23 insertions(+)
New commits:
commit 9a67bcf27554ee0688198e4d4eb5e541861bf7cb
Author: Tom Gundersen <teg at jklm.no>
Date: Fri Nov 7 19:19:02 2014 +0100
shared: add readlink_value
Reads the basename of the target of a symlink.
diff --git a/src/shared/util.c b/src/shared/util.c
index 3411cea..f0e0c0d 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;
diff --git a/src/shared/util.h b/src/shared/util.h
index 24480be..04f2d8a 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -270,6 +270,7 @@ char **replace_env_argv(char **argv, char **env);
int readlinkat_malloc(int fd, const char *p, char **ret);
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);
More information about the systemd-commits
mailing list