diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-01-26 21:39:06 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-01-26 21:39:06 +0100 |
commit | 87f0e418cf2c58b3201d06a60e3696ec672d2662 (patch) | |
tree | a27ef34fdf69505d983852d36d200b6e590726df /util.c | |
parent | fd79db6a5df0f94c48736ce5aa0131d6ab108fb0 (diff) |
s/name/unit
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -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; +} |