aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-10-01 04:10:44 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2016-10-01 04:10:44 +0200
commitb07d9df5fc905abebdbda833daf5dd6b8cf08688 (patch)
treeb73d16be97b01deea3ec92bc068584d579ffdcda
parent3cc975bb2a80ebe5b451d268ae0562f1a0cbe126 (diff)
downloadliberty-b07d9df5fc905abebdbda833daf5dd6b8cf08688.tar.gz
liberty-b07d9df5fc905abebdbda833daf5dd6b8cf08688.tar.xz
liberty-b07d9df5fc905abebdbda833daf5dd6b8cf08688.zip
Simplify resolve_relative_filename_generic()
-rw-r--r--liberty.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/liberty.c b/liberty.c
index 4980a53..e87d47c 100644
--- a/liberty.c
+++ b/liberty.c
@@ -3187,29 +3187,21 @@ static char *
resolve_relative_filename_generic
(struct str_vector *paths, const char *tail, const char *filename)
{
- struct str file;
- str_init (&file);
-
- char *result = NULL;
for (unsigned i = 0; i < paths->len; i++)
{
// As per XDG spec, relative paths are ignored
if (*paths->vector[i] != '/')
continue;
- str_reset (&file);
- str_append_printf (&file, "%s/%s%s", paths->vector[i], tail, filename);
+ char *file = xstrdup_printf
+ ("%s/%s%s", paths->vector[i], tail, filename);
struct stat st;
- if (!stat (file.str, &st))
- {
- result = str_steal (&file);
- break;
- }
+ if (!stat (file, &st))
+ return file;
+ free (file);
}
-
- str_free (&file);
- return result;
+ return NULL;
}
static void