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 #include #include +#include #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