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.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 179a1a305d1..2376bd82b69 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -123,7 +123,7 @@ int BLI_path_sequence_decode(const char *string, char *head, char *tail, ushort
void BLI_path_sequence_encode(
char *string, const char *head, const char *tail, ushort numlen, int pic)
{
- sprintf(string, "%s%.*d%s", head, numlen, MAX2(0, pic), tail);
+ BLI_sprintf(string, "%s%.*d%s", head, numlen, MAX2(0, pic), tail);
}
static int BLI_path_unc_prefix_len(const char *path); /* defined below in same file */
@@ -620,23 +620,12 @@ bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char
}
BLI_strncpy(extension, string + a, sizeof(extension));
- sprintf(string + a, "%s%s%s", sep, suffix, extension);
+ BLI_sprintf(string + a, "%s%s%s", sep, suffix, extension);
return true;
}
bool BLI_path_parent_dir(char *path)
{
- char tmp[FILE_MAX];
-
- STRNCPY(tmp, path);
- /* Does all the work of normalizing the path for us.
- *
- * NOTE(@campbellbarton): While it's possible strip text after the second last slash,
- * this would have to be clever and skip cases like "/./" & multiple slashes.
- * Since this ends up solving some of the same problems as #BLI_path_normalize,
- * call this function instead of attempting to handle them separately. */
- BLI_path_normalize(NULL, tmp);
-
/* Use #BLI_path_name_at_index instead of checking if the strings ends with `parent_dir`
* to ensure the logic isn't confused by:
* - Directory names that happen to end with `..`.
@@ -644,18 +633,19 @@ bool BLI_path_parent_dir(char *path)
* which would cause checking for a tailing `/../` fail.
* Extracting the span of the final directory avoids both these issues. */
int tail_ofs = 0, tail_len = 0;
- if (!BLI_path_name_at_index(tmp, -1, &tail_ofs, &tail_len)) {
+ if (!BLI_path_name_at_index(path, -1, &tail_ofs, &tail_len)) {
return false;
}
if (tail_len == 1) {
/* Last path is ".", as normalize should remove this, it's safe to assume failure.
* This happens when the input a single period (possibly with slashes before or after). */
- if (tmp[tail_ofs] == '.') {
+ if (path[tail_ofs] == '.') {
return false;
}
}
- memcpy(path, tmp, tail_ofs);
+ /* Input paths should already be normalized if `..` is part of the path. */
+ BLI_assert(!((tail_len == 2) && (path[tail_ofs] == '.') && (path[tail_ofs + 1] == '.')));
path[tail_ofs] = '\0';
return true;
}