From a4e92c8ad6051f58db33788306e7877934bfe230 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Fri, 30 Jun 2006 14:14:40 +0000 Subject: [PATCH] in striponedir(), return the stripped path instead of modifying path git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3704 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 3 ++- src/browser.c | 21 +++++++++++++-------- src/proto.h | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6b39019c..e6a3662e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -30,7 +30,8 @@ CVS code - striponedir() - Since all the strings passed to this are dynamically allocated, use null_at() to strip the directory from the - string. (DLR) + string. Also, return the stripped path instead of modifying + path. (DLR) - doc/syntax/c.nanorc: - Since .i and .ii are preprocessed C and C++ output, colorize them here. (Mike Frysinger) diff --git a/src/browser.c b/src/browser.c index 051d2512..6caa4764 100644 --- a/src/browser.c +++ b/src/browser.c @@ -333,7 +333,7 @@ char *do_browser(char *path, DIR *dir) } else if (strcmp(tail(filelist[selected]), "..") == 0) { prev_dir = mallocstrcpy(NULL, filelist[selected]); - striponedir(prev_dir); + prev_dir = striponedir(prev_dir); } dir = opendir(filelist[selected]); @@ -401,7 +401,7 @@ char *do_browse_from(const char *inpath) * at all. If so, we'll just pass the current directory to * do_browser(). */ if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) { - striponedir(path); + path = striponedir(path); if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) { free(path); @@ -966,18 +966,23 @@ void do_last_file(void) selected = filelist_len - 1; } -/* Strip one directory from the end of path, which should be - * dynamically allocated. */ -void striponedir(char *path) +/* Strip one directory from the end of path, and return the stripped + * path. The returned string is dynamically allocated, and should be + * freed. */ +char *striponedir(const char *path) { - char *tmp; + char *retval, *tmp; assert(path != NULL); - tmp = strrchr(path, '/'); + retval = mallocstrcpy(NULL, path); + + tmp = strrchr(retval, '/'); if (tmp != NULL) - null_at(&path, tmp - path); + null_at(&retval, tmp - retval); + + return retval; } #endif /* !DISABLE_BROWSER */ diff --git a/src/proto.h b/src/proto.h index c746ef1b..21c36969 100644 --- a/src/proto.h +++ b/src/proto.h @@ -157,7 +157,7 @@ void do_filesearch(void); void do_fileresearch(void); void do_first_file(void); void do_last_file(void); -void striponedir(char *path); +char *striponedir(const char *path); #endif /* Public functions in chars.c. */ -- 2.39.5