This will make a relative path absolute and clean it up via clean_fname(). * Returns the string, which might be newly allocated, or NULL on error. */
| 1243 | /* This will make a relative path absolute and clean it up via clean_fname(). |
| 1244 | * Returns the string, which might be newly allocated, or NULL on error. */ |
| 1245 | char *normalize_path(char *path, BOOL force_newbuf, unsigned int *len_ptr) |
| 1246 | { |
| 1247 | unsigned int len; |
| 1248 | |
| 1249 | if (*path != '/') { /* Make path absolute. */ |
| 1250 | int len = strlen(path); |
| 1251 | if (curr_dir_len + 1 + len >= sizeof curr_dir) |
| 1252 | return NULL; |
| 1253 | curr_dir[curr_dir_len] = '/'; |
| 1254 | memcpy(curr_dir + curr_dir_len + 1, path, len + 1); |
| 1255 | path = strdup(curr_dir); |
| 1256 | curr_dir[curr_dir_len] = '\0'; |
| 1257 | } else if (force_newbuf) |
| 1258 | path = strdup(path); |
| 1259 | |
| 1260 | len = clean_fname(path, CFN_COLLAPSE_DOT_DOT_DIRS | CFN_DROP_TRAILING_DOT_DIR); |
| 1261 | |
| 1262 | if (len_ptr) |
| 1263 | *len_ptr = len; |
| 1264 | |
| 1265 | return path; |
| 1266 | } |
| 1267 | |
| 1268 | /** |
| 1269 | * Return a quoted string with the full pathname of the indicated filename. |
no test coverage detected