diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/igt_core.c | 16 | ||||
| -rw-r--r-- | lib/igt_core.h | 13 |
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/igt_core.c b/lib/igt_core.c index 783a2191..8d609304 100644 --- a/lib/igt_core.c +++ b/lib/igt_core.c @@ -54,6 +54,7 @@ #include <errno.h> #include <time.h> #include <ctype.h> +#include <limits.h> #include "drmtest.h" #include "intel_chipset.h" @@ -1735,3 +1736,18 @@ void igt_set_timeout(unsigned int seconds) alarm(seconds); } + +FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir, + const char* filename) +{ + char path[PATH_MAX]; + FILE *fp; + + snprintf(path, sizeof(path), "%s/%s", igt_datadir, filename); + fp = fopen(path, "r"); + if (!fp) { + snprintf(path, sizeof(path), "%s/%s", igt_srcdir, filename); + fp = fopen(path, "r"); + } + return fp; +} diff --git a/lib/igt_core.h b/lib/igt_core.h index 33f89406..4e56be8a 100644 --- a/lib/igt_core.h +++ b/lib/igt_core.h @@ -33,6 +33,7 @@ #include <setjmp.h> #include <stdbool.h> #include <stdlib.h> +#include <stdio.h> #include <string.h> #include <sys/types.h> #include <stdarg.h> @@ -650,4 +651,16 @@ extern enum igt_log_level igt_log_level; void igt_set_timeout(unsigned int seconds); +FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir, + const char* filename); +/** + * igt_fopen_data: + * @filename: filename to open. + * + * Open a datafile for test, first try from installation directory + * then from build directory. + */ +#define igt_fopen_data(filename) \ + __igt_fopen_data(IGT_SRCDIR, IGT_DATADIR, filename) + #endif /* IGT_CORE_H */ |
