diff options
author | Peter Kim <pk15950@gmail.com> | 2021-10-03 06:22:05 +0300 |
---|---|---|
committer | Peter Kim <pk15950@gmail.com> | 2021-10-03 06:22:05 +0300 |
commit | 6fc81d6bca6424a1e44305df7cdc3598e03b00ba (patch) | |
tree | a66f17c5378f2a68f4c5d8b09f56687c3d9bf888 /source/blender/blenlib/intern/path_util.c | |
parent | 85e1f28fcaafd137a546bf192777b00f96851e80 (diff) | |
parent | d3afe0c1265c9ebb53053de68f176b30f0132281 (diff) |
Merge branch 'master' into xr-controller-supportxr-controller-support
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 33 |
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. */ |