diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index c626e32cfe2..37458402bd2 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -278,6 +278,11 @@ bool BLI_path_extension_glob_validate(char *ext_fnmatch) ATTR_NONNULL(); * \return false if there was no room. */ bool BLI_path_extension_replace(char *path, size_t maxlen, const char *ext) ATTR_NONNULL(); +/** + * Remove the file extension. + * \return true if a change was made to `path`. + */ +bool BLI_path_extension_strip(char *path) ATTR_NONNULL(); /** * Strip's trailing '.'s and adds the extension only when needed */ diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index a3077f536fa..6047c381ff3 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -820,8 +820,7 @@ void BLI_path_to_display_name(char *display_name, int maxlen, const char *name) /* Replace underscores with spaces. */ BLI_str_replace_char(display_name, '_', ' '); - /* Strip extension. */ - BLI_path_extension_replace(display_name, maxlen, ""); + BLI_path_extension_strip(display_name); /* Test if string has any upper case characters. */ bool all_lower = true; @@ -1279,6 +1278,16 @@ bool BLI_path_extension_replace(char *path, size_t maxlen, const char *ext) return true; } +bool BLI_path_extension_strip(char *path) +{ + char *path_ext = (char *)BLI_path_extension(path); + if (path_ext == NULL) { + return false; + } + *path_ext = '\0'; + return true; +} + bool BLI_path_extension_ensure(char *path, size_t maxlen, const char *ext) { #ifdef DEBUG_STRSIZE diff --git a/source/blender/editors/object/object_volume.c b/source/blender/editors/object/object_volume.c index 9ad26095bae..84d2f69497f 100644 --- a/source/blender/editors/object/object_volume.c +++ b/source/blender/editors/object/object_volume.c @@ -80,7 +80,7 @@ static int volume_import_exec(bContext *C, wmOperator *op) LISTBASE_FOREACH (ImageFrameRange *, range, &ranges) { char filename[FILE_MAX]; BLI_split_file_part(range->filepath, filename, sizeof(filename)); - BLI_path_extension_replace(filename, sizeof(filename), ""); + BLI_path_extension_strip(filename); Object *object = object_volume_add(C, op, filename); Volume *volume = (Volume *)object->data; diff --git a/source/blender/editors/screen/screendump.c b/source/blender/editors/screen/screendump.c index 5d9cb4be166..4d44999f1f3 100644 --- a/source/blender/editors/screen/screendump.c +++ b/source/blender/editors/screen/screendump.c @@ -170,7 +170,7 @@ static int screenshot_invoke(bContext *C, wmOperator *op, const wmEvent *event) const char *blendfile_path = BKE_main_blendfile_path_from_global(); if (blendfile_path[0] != '\0') { BLI_strncpy(filepath, blendfile_path, sizeof(filepath)); - BLI_path_extension_replace(filepath, sizeof(filepath), ""); /* strip '.blend' */ + BLI_path_extension_strip(filepath); /* Strip `.blend`. */ } else { /* As the file isn't saved, only set the name and let the file selector pick a directory. */ diff --git a/source/blender/editors/space_file/filelist.cc b/source/blender/editors/space_file/filelist.cc index f077b0d54ef..4434f93c525 100644 --- a/source/blender/editors/space_file/filelist.cc +++ b/source/blender/editors/space_file/filelist.cc @@ -3030,7 +3030,7 @@ static int filelist_readjob_list_dir(FileListReadJob *job_params, target = entry->redirection_path; #ifdef WIN32 /* On Windows don't show `.lnk` extension for valid shortcuts. */ - BLI_path_extension_replace(entry->relpath, FILE_MAXDIR, ""); + BLI_path_extension_strip(entry->relpath); #endif } else { diff --git a/source/blender/io/ply/importer/ply_import.cc b/source/blender/io/ply/importer/ply_import.cc index 6d7d2488f89..a17aa51bf23 100644 --- a/source/blender/io/ply/importer/ply_import.cc +++ b/source/blender/io/ply/importer/ply_import.cc @@ -171,7 +171,7 @@ void importer_main(Main *bmain, /* File base name used for both mesh and object. */ char ob_name[FILE_MAX]; BLI_strncpy(ob_name, BLI_path_basename(import_params.filepath), FILE_MAX); - BLI_path_extension_replace(ob_name, FILE_MAX, ""); + BLI_path_extension_strip(ob_name); /* Parse header. */ PlyReadBuffer file(import_params.filepath, 64 * 1024); diff --git a/source/blender/io/stl/importer/stl_import.cc b/source/blender/io/stl/importer/stl_import.cc index 2f32b9270f3..9ca002b71e8 100644 --- a/source/blender/io/stl/importer/stl_import.cc +++ b/source/blender/io/stl/importer/stl_import.cc @@ -76,7 +76,7 @@ void importer_main(Main *bmain, /* Name used for both mesh and object. */ char ob_name[FILE_MAX]; BLI_strncpy(ob_name, BLI_path_basename(import_params.filepath), FILE_MAX); - BLI_path_extension_replace(ob_name, FILE_MAX, ""); + BLI_path_extension_strip(ob_name); Mesh *mesh = nullptr; if (is_ascii_stl) { diff --git a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc index f3d379c620c..c49436e3e8e 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc @@ -304,7 +304,7 @@ void export_frame(Depsgraph *depsgraph, const OBJExportParams &export_params, co bool append_frame_to_filename(const char *filepath, const int frame, char *r_filepath_with_frames) { BLI_strncpy(r_filepath_with_frames, filepath, FILE_MAX); - BLI_path_extension_replace(r_filepath_with_frames, FILE_MAX, ""); + BLI_path_extension_strip(r_filepath_with_frames); const int digits = frame == 0 ? 1 : integer_digits_i(abs(frame)); BLI_path_frame(r_filepath_with_frames, frame, digits); return BLI_path_extension_replace(r_filepath_with_frames, FILE_MAX, ".obj"); diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index d21ff66032e..0e02fd9336e 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -489,7 +489,7 @@ void OBJParser::parse(Vector> &r_all_geometries, /* Use the filename as the default name given to the initial object. */ char ob_name[FILE_MAXFILE]; BLI_strncpy(ob_name, BLI_path_basename(import_params_.filepath), FILE_MAXFILE); - BLI_path_extension_replace(ob_name, FILE_MAXFILE, ""); + BLI_path_extension_strip(ob_name); Geometry *curr_geom = create_geometry(nullptr, GEOM_MESH, ob_name, r_all_geometries); diff --git a/source/blender/render/intern/render_result.cc b/source/blender/render/intern/render_result.cc index 65463321f8c..4383f30c5aa 100644 --- a/source/blender/render/intern/render_result.cc +++ b/source/blender/render/intern/render_result.cc @@ -852,7 +852,7 @@ static void render_result_exr_file_cache_path(Scene *sce, const char *blendfile_path = BKE_main_blendfile_path_from_global(); if (blendfile_path[0] != '\0') { BLI_split_dirfile(blendfile_path, dirname, filename, sizeof(dirname), sizeof(filename)); - BLI_path_extension_replace(filename, sizeof(filename), ""); /* strip '.blend' */ + BLI_path_extension_strip(filename); /* Strip `.blend`. */ BLI_hash_md5_buffer(blendfile_path, strlen(blendfile_path), path_digest); } else {