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>
This commit is contained in:
parent
598ee9ddf5
commit
83b900fb46
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user