summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-02-11 16:45:35 +0100
committerLennart Poettering <lennart@poettering.net>2014-02-11 17:16:08 +0100
commit2d2ebd6b8f0775b93480bf05464865a0c78a9390 (patch)
treef726e2af84e9023b0bc381590d8abc32bc31c656 /src/shared
parentc50e4f95d8cfcd21bde2b0d1ff24b4de8fef4976 (diff)
util: modernize readlink_malloc() a bit
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 21edd3ac2f..9be11f5605 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -761,28 +761,31 @@ char *strappend(const char *s, const char *suffix) {
return strnappend(s, suffix, suffix ? strlen(suffix) : 0);
}
-int readlink_malloc(const char *p, char **r) {
+int readlink_malloc(const char *p, char **ret) {
size_t l = 100;
+ int r;
assert(p);
- assert(r);
+ assert(ret);
for (;;) {
char *c;
ssize_t n;
- if (!(c = new(char, l)))
+ c = new(char, l);
+ if (!c)
return -ENOMEM;
- if ((n = readlink(p, c, l-1)) < 0) {
- int ret = -errno;
+ n = readlink(p, c, l-1);
+ if (n < 0) {
+ r = -errno;
free(c);
- return ret;
+ return r;
}
if ((size_t) n < l-1) {
c[n] = 0;
- *r = c;
+ *ret = c;
return 0;
}