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:
authorCampbell Barton <ideasman42@gmail.com>2011-10-31 04:23:42 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-10-31 04:23:42 +0400
commitdc1b3d88b821db1316c85be5f48a60107796b651 (patch)
treed2996b5c4c21ee4b0d0233483e39094bdb1e80d9 /source/blender/blenlib/intern
parentd3f63bf54cb214fc7cb67b8741dc21fc67b5937a (diff)
fix [#29098] File save dialog cannot handle extra periods in file name
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r--source/blender/blenlib/intern/path_util.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index e03a7baca0c..bbb62db58f2 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1397,22 +1397,51 @@ int BLI_testextensie_glob(const char *str, const char *ext_fnmatch)
int BLI_replace_extension(char *path, size_t maxlen, const char *ext)
{
+ size_t path_len= strlen(path);
+ size_t ext_len= strlen(ext);
size_t a;
- for(a=strlen(path); a>0; a--) {
- if(path[a-1] == '.' || path[a-1] == '/' || path[a-1] == '\\') {
- a--;
+ for(a= path_len - 1; a >= 0; a--) {
+ if (ELEM3(path[a], '.', '/', '\\')) {
break;
}
}
-
- if(path[a] != '.')
- a= strlen(path);
- if(a + strlen(ext) >= maxlen)
+ if(a + ext_len >= maxlen)
+ return 0;
+
+ memcpy(path+a, ext, ext_len + 1);
+ return 1;
+}
+
+/* strip's trailing '.'s and adds the extension only when needed */
+int BLI_ensure_extension(char *path, size_t maxlen, const char *ext)
+{
+ size_t path_len= strlen(path);
+ size_t ext_len= strlen(ext);
+ size_t a;
+
+ /* first check the extension is alread there */
+ if ( (ext_len <= path_len) &&
+ (strcmp(path + (path_len - ext_len), ext) == 0))
+ {
+ return 1;
+ }
+
+ for(a= path_len - 1; a >= 0; a--) {
+ if (path[a] == '.') {
+ path[a]= '\0';
+ }
+ else {
+ break;
+ }
+ }
+ a++;
+
+ if(a + ext_len >= maxlen)
return 0;
- strcpy(path+a, ext);
+ memcpy(path+a, ext, ext_len + 1);
return 1;
}