summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorDerek Foreman <derekf@osg.samsung.com>2018-02-06 15:18:36 -0600
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2018-02-07 11:38:21 +0200
commit83b900fb4649346162e8f8165bcff1927177c31f (patch)
tree0e0be6415d8a0a5c17a07853a624c91a0abc5345 /shared
parent598ee9ddf53f17494e7e1e83d8d576712f0dad19 (diff)
downloadweston-83b900fb4649346162e8f8165bcff1927177c31f.tar.gz
shared: Add a function to prefix filenames with datadir
Currently we look for png files in their install directory, and we manufacture filenames with string pasting at compile time. This new function will allow overriding the compile time setting with the env var WESTON_DATA_DIR so we can do neat tricks like allow our test suite to pass when we haven't yet installed icons system-wide. Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Acked-by: Daniel Stone <daniels@collabora.com> Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net> [Pekka: split if-branch into two lines.] Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Diffstat (limited to 'shared')
-rw-r--r--shared/file-util.c19
-rw-r--r--shared/file-util.h3
2 files changed, 22 insertions, 0 deletions
diff --git a/shared/file-util.c b/shared/file-util.c
index 979a3811..e254217c 100644
--- a/shared/file-util.c
+++ b/shared/file-util.c
@@ -31,6 +31,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <stdlib.h>
#include "file-util.h"
@@ -119,3 +120,21 @@ file_create_dated(const char *path_prefix, const char *suffix,
return fdopen(fd, "w");
}
+
+char *
+file_name_with_datadir(const char *filename)
+{
+ const char *base = getenv("WESTON_DATA_DIR");
+ char *out;
+ int len;
+
+ if (base)
+ len = asprintf(&out, "%s/%s", base, filename);
+ else
+ len = asprintf(&out, "%s/weston/%s", DATADIR, filename);
+
+ if (len == -1)
+ return NULL;
+
+ return out;
+}
diff --git a/shared/file-util.h b/shared/file-util.h
index f639c446..dbda07a8 100644
--- a/shared/file-util.h
+++ b/shared/file-util.h
@@ -36,6 +36,9 @@ FILE *
file_create_dated(const char *path_prefix, const char *suffix,
char *name_out, size_t name_len);
+char *
+file_name_with_datadir(const char *);
+
#ifdef __cplusplus
}
#endif