diff --git a/src/xrt/auxiliary/util/u_config_json.c b/src/xrt/auxiliary/util/u_config_json.c index e8dd818e1..d89a720ce 100644 --- a/src/xrt/auxiliary/util/u_config_json.c +++ b/src/xrt/auxiliary/util/u_config_json.c @@ -61,7 +61,7 @@ u_config_json_open_or_create_file(struct u_config_json *json, const char *filena json->file_loaded = true; - char *str = u_file_read_content(file); + char *str = u_file_read_content(file, NULL); fclose(file); if (str == NULL) { U_LOG_E("Could not read the contents of '%s'!", tmp); diff --git a/src/xrt/auxiliary/util/u_file.c b/src/xrt/auxiliary/util/u_file.c index f1d5697e9..06241aecf 100644 --- a/src/xrt/auxiliary/util/u_file.c +++ b/src/xrt/auxiliary/util/u_file.c @@ -218,7 +218,7 @@ u_file_get_path_in_runtime_dir(const char *suffix, char *out_path, size_t out_pa } char * -u_file_read_content(FILE *file) +u_file_read_content(FILE *file, size_t *out_file_size) { // Go to the end of the file. fseek(file, 0L, SEEK_END); @@ -239,17 +239,20 @@ u_file_read_content(FILE *file) return NULL; } + if (out_file_size) + *out_file_size = file_size; + return buffer; } char * -u_file_read_content_from_path(const char *path) +u_file_read_content_from_path(const char *path, size_t *out_file_size) { FILE *file = fopen(path, "rb"); if (file == NULL) { return NULL; } - char *file_content = u_file_read_content(file); + char *file_content = u_file_read_content(file, out_file_size); int ret = fclose(file); // We don't care about the return value since we're just reading (void)ret; diff --git a/src/xrt/auxiliary/util/u_file.h b/src/xrt/auxiliary/util/u_file.h index 753a334db..ae7117863 100644 --- a/src/xrt/auxiliary/util/u_file.h +++ b/src/xrt/auxiliary/util/u_file.h @@ -38,10 +38,10 @@ ssize_t u_file_get_runtime_dir(char *out_path, size_t out_path_size); char * -u_file_read_content(FILE *file); +u_file_read_content(FILE *file, size_t *out_file_size); char * -u_file_read_content_from_path(const char *path); +u_file_read_content_from_path(const char *path, size_t *out_file_size); ssize_t u_file_get_path_in_runtime_dir(const char *suffix, char *out_path, size_t out_path_size); diff --git a/src/xrt/targets/common/target_builder_north_star.c b/src/xrt/targets/common/target_builder_north_star.c index 87261543f..a4a24b04c 100644 --- a/src/xrt/targets/common/target_builder_north_star.c +++ b/src/xrt/targets/common/target_builder_north_star.c @@ -116,7 +116,7 @@ struct ns_builder static bool ns_config_load(struct ns_builder *nsb) { - const char *file_content = u_file_read_content_from_path(nsb->config_path); + const char *file_content = u_file_read_content_from_path(nsb->config_path, NULL); if (file_content == NULL) { U_LOG_E("The file at \"%s\" was unable to load. Either there wasn't a file there or it was empty.", nsb->config_path); diff --git a/src/xrt/targets/common/target_builder_simulavr.c b/src/xrt/targets/common/target_builder_simulavr.c index 3ae7e07fe..914c1b339 100644 --- a/src/xrt/targets/common/target_builder_simulavr.c +++ b/src/xrt/targets/common/target_builder_simulavr.c @@ -71,7 +71,7 @@ process_poly_values(const cJSON *values, struct svr_display_distortion_polynomia static bool process_config(const char *config_path, struct svr_two_displays_distortion *out_dist) { - char *file_content = u_file_read_content_from_path(config_path); + char *file_content = u_file_read_content_from_path(config_path, NULL); if (file_content == NULL) { U_LOG_E("The file at \"%s\" was unable to load. Either there wasn't a file there or it was empty.", config_path);