Cleanup: replace BLI_snprintf with BLI_path_join

Also use a larger buffer to account for the unlikely case of the
buffer not being big enough for the appended directories.
This commit is contained in:
2022-09-12 10:10:54 +10:00
parent cf9c0a4b50
commit f884a34cae
4 changed files with 30 additions and 22 deletions

View File

@@ -371,14 +371,16 @@ static bool get_path_local_ex(char *targetpath,
relfolder[0] = '\0';
}
/* Try `{g_app.program_dirname}/2.xx/{folder_name}` the default directory
/* Try `{g_app.program_dirname}/3.xx/{folder_name}` the default directory
* for a portable distribution. See `WITH_INSTALL_PORTABLE` build-option. */
const char *path_base = g_app.program_dirname;
#if defined(__APPLE__) && !defined(WITH_PYTHON_MODULE)
/* Due new code-sign situation in OSX > 10.9.5
* we must move the blender_version dir with contents to Resources. */
char osx_resourses[FILE_MAX];
BLI_snprintf(osx_resourses, sizeof(osx_resourses), "%s../Resources", g_app.program_dirname);
* we must move the blender_version dir with contents to Resources.
* Add 4 + 9 for the temporary `/../` path & `Resources`. */
char osx_resourses[FILE_MAX + 4 + 9];
BLI_path_join(
osx_resourses, sizeof(osx_resourses), g_app.program_dirname, "..", "Resources", NULL);
/* Remove the '/../' added above. */
BLI_path_normalize(NULL, osx_resourses);
path_base = osx_resourses;

View File

@@ -175,12 +175,12 @@ bool BKE_image_save_options_init(ImageSaveOptions *opts,
BLI_strncpy(opts->filepath, G.ima, sizeof(opts->filepath));
}
else {
BLI_snprintf(opts->filepath, sizeof(opts->filepath), "//%s", DATA_("untitled"));
BLI_path_join(opts->filepath, sizeof(opts->filepath), "//", DATA_("untitled"), nullptr);
BLI_path_abs(opts->filepath, BKE_main_blendfile_path(bmain));
}
}
else {
BLI_snprintf(opts->filepath, sizeof(opts->filepath), "//%s", ima->id.name + 2);
BLI_path_join(opts->filepath, sizeof(opts->filepath), "//", ima->id.name + 2, nullptr);
BLI_path_make_safe(opts->filepath);
BLI_path_abs(opts->filepath, is_prev_save ? G.ima : BKE_main_blendfile_path(bmain));
}

View File

@@ -526,22 +526,28 @@ static void unpack_generate_paths(const char *name,
BLI_strncpy(tempdir, "//", sizeof(tempdir));
}
{
const char *dir_name = NULL;
switch (id_type) {
case ID_VF:
BLI_snprintf(r_relpath, relpathlen, "//fonts/%s", tempname);
dir_name = "fonts";
break;
case ID_SO:
BLI_snprintf(r_relpath, relpathlen, "//sounds/%s", tempname);
dir_name = "sounds";
break;
case ID_IM:
BLI_snprintf(r_relpath, relpathlen, "//textures/%s", tempname);
dir_name = "textures";
break;
case ID_VO:
BLI_snprintf(r_relpath, relpathlen, "//volumes/%s", tempname);
dir_name = "volumes";
break;
default:
break;
}
if (dir_name) {
BLI_path_join(r_relpath, relpathlen, "//", dir_name, tempname, NULL);
}
}
{
size_t len = BLI_strncpy_rlen(r_abspath, tempdir, abspathlen);

View File

@@ -377,7 +377,7 @@ void unpack_menu(bContext *C,
char local_name[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX];
BLI_split_file_part(abs_name, fi, sizeof(fi));
BLI_snprintf(local_name, sizeof(local_name), "//%s/%s", folder, fi);
BLI_path_join(local_name, sizeof(local_name), "//", folder, fi, NULL);
if (!STREQ(abs_name, local_name)) {
switch (BKE_packedfile_compare_to_file(blendfile_path, local_name, pf)) {
case PF_CMP_NOFILE: