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)
} 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]);
* 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);
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 */
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. */