The open source OpenXR runtime

a/util: Add optional file size output for u_file_read_content*

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2459>

+11 -8
+1 -1
src/xrt/auxiliary/util/u_config_json.c
··· 61 61 62 62 json->file_loaded = true; 63 63 64 - char *str = u_file_read_content(file); 64 + char *str = u_file_read_content(file, NULL); 65 65 fclose(file); 66 66 if (str == NULL) { 67 67 U_LOG_E("Could not read the contents of '%s'!", tmp);
+6 -3
src/xrt/auxiliary/util/u_file.c
··· 218 218 } 219 219 220 220 char * 221 - u_file_read_content(FILE *file) 221 + u_file_read_content(FILE *file, size_t *out_file_size) 222 222 { 223 223 // Go to the end of the file. 224 224 fseek(file, 0L, SEEK_END); ··· 239 239 return NULL; 240 240 } 241 241 242 + if (out_file_size) 243 + *out_file_size = file_size; 244 + 242 245 return buffer; 243 246 } 244 247 245 248 char * 246 - u_file_read_content_from_path(const char *path) 249 + u_file_read_content_from_path(const char *path, size_t *out_file_size) 247 250 { 248 251 FILE *file = fopen(path, "rb"); 249 252 if (file == NULL) { 250 253 return NULL; 251 254 } 252 - char *file_content = u_file_read_content(file); 255 + char *file_content = u_file_read_content(file, out_file_size); 253 256 int ret = fclose(file); 254 257 // We don't care about the return value since we're just reading 255 258 (void)ret;
+2 -2
src/xrt/auxiliary/util/u_file.h
··· 38 38 u_file_get_runtime_dir(char *out_path, size_t out_path_size); 39 39 40 40 char * 41 - u_file_read_content(FILE *file); 41 + u_file_read_content(FILE *file, size_t *out_file_size); 42 42 43 43 char * 44 - u_file_read_content_from_path(const char *path); 44 + u_file_read_content_from_path(const char *path, size_t *out_file_size); 45 45 46 46 ssize_t 47 47 u_file_get_path_in_runtime_dir(const char *suffix, char *out_path, size_t out_path_size);
+1 -1
src/xrt/targets/common/target_builder_north_star.c
··· 116 116 static bool 117 117 ns_config_load(struct ns_builder *nsb) 118 118 { 119 - const char *file_content = u_file_read_content_from_path(nsb->config_path); 119 + const char *file_content = u_file_read_content_from_path(nsb->config_path, NULL); 120 120 if (file_content == NULL) { 121 121 U_LOG_E("The file at \"%s\" was unable to load. Either there wasn't a file there or it was empty.", 122 122 nsb->config_path);
+1 -1
src/xrt/targets/common/target_builder_simulavr.c
··· 71 71 static bool 72 72 process_config(const char *config_path, struct svr_two_displays_distortion *out_dist) 73 73 { 74 - char *file_content = u_file_read_content_from_path(config_path); 74 + char *file_content = u_file_read_content_from_path(config_path, NULL); 75 75 if (file_content == NULL) { 76 76 U_LOG_E("The file at \"%s\" was unable to load. Either there wasn't a file there or it was empty.", 77 77 config_path);