[Bf-blender-cvs] [d8b34a17ac] master: Cleanup: remove BLI_getlastdir

Campbell Barton noreply at git.blender.org
Wed Mar 22 20:33:51 CET 2017


Commit: d8b34a17ac4375cf4618974626c6ba2643603590
Author: Campbell Barton
Date:   Thu Mar 23 06:32:16 2017 +1100
Branches: master
https://developer.blender.org/rBd8b34a17ac4375cf4618974626c6ba2643603590

Cleanup: remove BLI_getlastdir

Replace with BLI_path_name_at_index

===================================================================

M	source/blender/blenlib/BLI_path_util.h
M	source/blender/blenlib/intern/path_util.c
M	source/blender/editors/space_file/fsmenu.c

===================================================================

diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index 7d971fbfc3..1c1725923a 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -86,7 +86,6 @@ bool BLI_path_program_extensions_add_win32(char *name, const size_t maxlen);
 #endif
 bool BLI_path_program_search(char *fullname, const size_t maxlen, const char *name);
 
-void BLI_getlastdir(const char *dir, char *last, const size_t maxlen);
 bool BLI_testextensie(const char *str, const char *ext) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 bool BLI_testextensie_n(const char *str, ...) ATTR_NONNULL(1) ATTR_SENTINEL(0);
 bool BLI_testextensie_array(const char *str, const char **ext_array) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 83aa01d3d1..955f603cda 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1167,30 +1167,6 @@ bool BLI_path_program_search(
 }
 
 /**
- * Copies into *last the part of *dir following the second-last slash.
- */
-void BLI_getlastdir(const char *dir, char *last, const size_t maxlen)
-{
-	const char *s = dir;
-	const char *lslash = NULL;
-	const char *prevslash = NULL;
-	while (*s) {
-		if ((*s == '\\') || (*s == '/')) {
-			prevslash = lslash;
-			lslash = s;
-		}
-		s++;
-	}
-	if (prevslash) {
-		BLI_strncpy(last, prevslash + 1, maxlen);
-	}
-	else {
-		BLI_strncpy(last, dir, maxlen);
-	}
-}
-
-
-/**
  * Sets the specified environment variable to the specified value,
  * and clears it if val == NULL.
  */
diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c
index d7aa1040e0..71d49e0dc2 100644
--- a/source/blender/editors/space_file/fsmenu.c
+++ b/source/blender/editors/space_file/fsmenu.c
@@ -169,12 +169,15 @@ void ED_fsmenu_entry_set_path(struct FSMenuEntry *fsentry, const char *path)
 
 static void fsmenu_entry_generate_name(struct FSMenuEntry *fsentry, char *name, size_t name_size)
 {
-	char temp[FILE_MAX];
+	int offset = 0;
+	int len = name_size;
 
-	BLI_strncpy(temp, fsentry->path, FILE_MAX);
-	BLI_add_slash(temp);
-	BLI_getlastdir(temp, name, name_size);
-	BLI_del_slash(name);
+	if (BLI_path_name_at_index(fsentry->path, -1, &offset, &len)) {
+		/* use as size */
+		len += 1;
+	}
+
+	BLI_strncpy(name, &fsentry->path[offset], MIN2(len, name_size));
 	if (!name[0]) {
 		name[0] = '/';
 		name[1] = '\0';




More information about the Bf-blender-cvs mailing list