BLI_path: add BLI_path_normalize_native for non-blend file paths
System paths with multiple leading slashes get normalized to one slash.
This commit is contained in:
@@ -155,6 +155,14 @@ void BLI_path_to_display_name(char *display_name, int display_name_maxncpy, cons
|
||||
* \param path: The path to a file or directory which can be absolute or relative.
|
||||
*/
|
||||
void BLI_path_normalize(char *path) ATTR_NONNULL(1);
|
||||
|
||||
/**
|
||||
* A version of #BLI_path_normalize without special handling of `//` blend file relative prefix.
|
||||
*
|
||||
* \note On UNIX `//path` is a valid path which gets normalized to `/path`.
|
||||
*/
|
||||
void BLI_path_normalize_native(char *path) ATTR_NONNULL(1);
|
||||
|
||||
/**
|
||||
* Cleanup file-path ensuring a trailing slash.
|
||||
*
|
||||
|
||||
@@ -135,7 +135,7 @@ void BLI_path_sequence_encode(char *path,
|
||||
BLI_snprintf(path, path_maxncpy, "%s%.*d%s", head, numlen, MAX2(0, pic), tail);
|
||||
}
|
||||
|
||||
void BLI_path_normalize(char *path)
|
||||
static void path_normalize_impl(char *path, bool check_blend_relative_prefix)
|
||||
{
|
||||
const char *path_orig = path;
|
||||
int path_len = strlen(path);
|
||||
@@ -144,7 +144,7 @@ void BLI_path_normalize(char *path)
|
||||
* Skip absolute prefix.
|
||||
* ---------------------
|
||||
*/
|
||||
if (path[0] == '/' && path[1] == '/') {
|
||||
if (check_blend_relative_prefix && (path[0] == '/' && path[1] == '/')) {
|
||||
path = path + 2; /* Leave the initial `//` untouched. */
|
||||
path_len -= 2;
|
||||
|
||||
@@ -357,6 +357,16 @@ void BLI_path_normalize(char *path)
|
||||
#undef IS_PARENT_DIR
|
||||
}
|
||||
|
||||
void BLI_path_normalize(char *path)
|
||||
{
|
||||
path_normalize_impl(path, true);
|
||||
}
|
||||
|
||||
void BLI_path_normalize_native(char *path)
|
||||
{
|
||||
path_normalize_impl(path, false);
|
||||
}
|
||||
|
||||
void BLI_path_normalize_dir(char *dir, size_t dir_maxncpy)
|
||||
{
|
||||
/* Would just create an unexpected "/" path, just early exit entirely. */
|
||||
|
||||
Reference in New Issue
Block a user