From d04139beddb807911251281d52ef096985dcd3fb Mon Sep 17 00:00:00 2001 From: Moses Turner Date: Sun, 18 Sep 2022 08:02:43 -0500 Subject: [PATCH] u/file: Add u_file_read_content_from_path Useful for Simula builder and North Star builder which both read straight from a path --- src/xrt/auxiliary/util/u_file.c | 16 ++++++++++++++++ src/xrt/auxiliary/util/u_file.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/xrt/auxiliary/util/u_file.c b/src/xrt/auxiliary/util/u_file.c index dcc9ab85d..01d112530 100644 --- a/src/xrt/auxiliary/util/u_file.c +++ b/src/xrt/auxiliary/util/u_file.c @@ -154,3 +154,19 @@ u_file_read_content(FILE *file) return buffer; } + +char * +u_file_read_content_from_path(const char *path) +{ + FILE *file = fopen(path, "r"); + if (file == NULL) { + return NULL; + } + char *file_content = u_file_read_content(file); + int ret = fclose(file); + // We don't care about the return value since we're just reading + (void)ret; + + // Either valid non-null or null + return file_content; +} diff --git a/src/xrt/auxiliary/util/u_file.h b/src/xrt/auxiliary/util/u_file.h index 1d68ca3d6..270802dc9 100644 --- a/src/xrt/auxiliary/util/u_file.h +++ b/src/xrt/auxiliary/util/u_file.h @@ -34,6 +34,9 @@ u_file_get_runtime_dir(char *out_path, size_t out_path_size); char * u_file_read_content(FILE *file); +char * +u_file_read_content_from_path(const char *path); + ssize_t u_file_get_path_in_runtime_dir(const char *suffix, char *out_path, size_t out_path_size);