Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r--source/blender/blenlib/intern/path_util.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 4d0678035ba..066749f3a94 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1935,6 +1935,39 @@ bool BLI_path_name_at_index(const char *__restrict path,
return false;
}
+bool BLI_path_contains(const char *container_path, const char *containee_path)
+{
+ char container_native[PATH_MAX];
+ char containee_native[PATH_MAX];
+
+ /* Keep space for a trailing slash. If the path is truncated by this, the containee path is
+ * longer than PATH_MAX and the result is ill-defined. */
+ BLI_strncpy(container_native, container_path, PATH_MAX - 1);
+ BLI_strncpy(containee_native, containee_path, PATH_MAX);
+
+ BLI_path_slash_native(container_native);
+ BLI_path_slash_native(containee_native);
+
+ BLI_path_normalize(NULL, container_native);
+ BLI_path_normalize(NULL, containee_native);
+
+#ifdef WIN32
+ BLI_str_tolower_ascii(container_native, PATH_MAX);
+ BLI_str_tolower_ascii(containee_native, PATH_MAX);
+#endif
+
+ if (STREQ(container_native, containee_native)) {
+ /* The paths are equal, they contain each other. */
+ return true;
+ }
+
+ /* Add a trailing slash to prevent same-prefix directories from matching.
+ * e.g. "/some/path" doesn't contain "/some/path_lib". */
+ BLI_path_slash_ensure(container_native);
+
+ return BLI_str_startswith(containee_native, container_native);
+}
+
/**
* Returns pointer to the leftmost path separator in string. Not actually used anywhere.
*/