The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

util/u_file: Add u_file_open_file_in_config_dir_subpath()

Add a utility function for accessing files in subdirectories
of the main config dir, creating the subpath as needed.

authored by

Jan Schmidt and committed by
Jakob Bornecrantz
ac84cd4d 2f3f9e0c

+36
+33
src/xrt/auxiliary/util/u_file.c
··· 119 119 return fopen(file_str, mode); 120 120 } 121 121 122 + FILE * 123 + u_file_open_file_in_config_dir_subpath(const char *subpath, const char *filename, const char *mode) 124 + { 125 + char tmp[PATH_MAX]; 126 + int i = u_file_get_config_dir(tmp, sizeof(tmp)); 127 + if (i < 0 || i >= (int)sizeof(tmp)) { 128 + return NULL; 129 + } 130 + 131 + char fullpath[PATH_MAX]; 132 + i = snprintf(fullpath, sizeof(fullpath), "%s/%s", tmp, subpath); 133 + if (i < 0 || i >= (int)sizeof(fullpath)) { 134 + return NULL; 135 + } 136 + 137 + char file_str[PATH_MAX + 15]; 138 + i = snprintf(file_str, sizeof(file_str), "%s/%s", fullpath, filename); 139 + if (i < 0 || i >= (int)sizeof(file_str)) { 140 + return NULL; 141 + } 142 + 143 + FILE *file = fopen(file_str, mode); 144 + if (file != NULL) { 145 + return file; 146 + } 147 + 148 + // Try creating the path. 149 + mkpath(fullpath); 150 + 151 + // Do not report error. 152 + return fopen(file_str, mode); 153 + } 154 + 122 155 ssize_t 123 156 u_file_get_hand_tracking_models_dir(char *out_path, size_t out_path_size) 124 157 {
+3
src/xrt/auxiliary/util/u_file.h
··· 28 28 FILE * 29 29 u_file_open_file_in_config_dir(const char *filename, const char *mode); 30 30 31 + FILE * 32 + u_file_open_file_in_config_dir_subpath(const char *subpath, const char *filename, const char *mode); 33 + 31 34 ssize_t 32 35 u_file_get_hand_tracking_models_dir(char *out_path, size_t out_path_size); 33 36