From e4def00d5bc8c4b2947f74d2b5c3308ae07a4eee Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 22 Sep 2008 15:37:32 +0000 Subject: fix for [#15020] File browser: going back from the root of all directories introduces "../" ad libitum + harcoded path? bug was introduced when fixing BLI_cleanup_dir not to write to negative character indicies. added a BLI_parent_dir(char *path) --- source/blender/blenlib/BLI_blenlib.h | 3 +++ source/blender/blenlib/intern/util.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/BLI_blenlib.h b/source/blender/blenlib/BLI_blenlib.h index 6a50e2de0e5..4bbda9709d7 100644 --- a/source/blender/blenlib/BLI_blenlib.h +++ b/source/blender/blenlib/BLI_blenlib.h @@ -137,6 +137,9 @@ void BLI_dlist_reinit(struct DynamicList *dlist); void BLI_cleanup_file(const char *relabase, char *dir); void BLI_cleanup_dir(const char *relabase, char *dir); /* same as above but adds a trailing slash */ +/* go back one directory */ +int BLI_parent_dir(char *path); + /** * Blender's path code replacement function. * Bases @a path strings leading with "//" by the diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c index 9dfe9557c1b..1630842be05 100644 --- a/source/blender/blenlib/intern/util.c +++ b/source/blender/blenlib/intern/util.c @@ -1058,6 +1058,21 @@ void BLI_makestringcode(const char *relfile, char *file) } } +int BLI_parent_dir(char *path) +{ + char tmp[FILE_MAXDIR+FILE_MAXFILE+4]; + BLI_strncpy(tmp, path, sizeof(tmp)); + BLI_add_slash(tmp); + strcat(tmp, "../"); + BLI_cleanup_dir(NULL, tmp); + + if (!BLI_testextensie(tmp, "../")) { + BLI_strncpy(path, tmp, sizeof(tmp)); + return 1; + } else { + return 0; + } +} int BLI_convertstringframe(char *path, int frame) { -- cgit v1.2.3