summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-01-26 21:39:06 +0100
committerLennart Poettering <lennart@poettering.net>2010-01-26 21:39:06 +0100
commit87f0e418cf2c58b3201d06a60e3696ec672d2662 (patch)
treea27ef34fdf69505d983852d36d200b6e590726df /util.c
parentfd79db6a5df0f94c48736ce5aa0131d6ab108fb0 (diff)
s/name/unit
Diffstat (limited to 'util.c')
-rw-r--r--util.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/util.c b/util.c
index b4b07e9d1b..f752a248ec 100644
--- a/util.c
+++ b/util.c
@@ -402,3 +402,44 @@ char *strappend(const char *s, const char *suffix) {
return r;
}
+
+int readlink_malloc(const char *p, char **r) {
+ size_t l = 100;
+
+ assert(p);
+ assert(r);
+
+ for (;;) {
+ char *c;
+ ssize_t n;
+
+ if (!(c = new(char, l)))
+ return -ENOMEM;
+
+ if ((n = readlink(p, c, l-1)) < 0) {
+ int ret = -errno;
+ free(c);
+ return ret;
+ }
+
+ if ((size_t) n < l-1) {
+ c[n] = 0;
+ *r = c;
+ return 0;
+ }
+
+ free(c);
+ l *= 2;
+ }
+}
+
+char *file_name_from_path(const char *p) {
+ char *r;
+
+ assert(p);
+
+ if ((r = strrchr(p, '/')))
+ return r + 1;
+
+ return (char*) p;
+}