summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c3fb219)
raw | patch | inline | side by side (parent: c3fb219)
author | Max Kellermann <max@duempel.org> | |
Fri, 7 Nov 2008 14:20:35 +0000 (15:20 +0100) | ||
committer | Max Kellermann <max@duempel.org> | |
Fri, 7 Nov 2008 14:20:35 +0000 (15:20 +0100) |
Don't allocate and copy memory.
src/screen_file.c | patch | blob | history |
diff --git a/src/screen_file.c b/src/screen_file.c
index 5a81e8fb8c0eccaeaf79f83acfee22d2736da4a4..75e4d163111e4fadec0d503f7577c3bd4aecff46 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.c
static const char *
browse_title(char *str, size_t size)
{
- char *dirname, *parentdir;
+ const char *path = NULL, *prev = NULL, *slash = browser.filelist->path;
- dirname = g_path_get_dirname(browser.filelist->path);
- parentdir = g_path_get_basename(dirname);
-
- if( parentdir[0] == '.' && strlen(parentdir) == 1 ) {
- parentdir = NULL;
+ /* determine the last 2 parts of the path */
+ while ((slash = strchr(slash, '/')) != NULL) {
+ path = prev;
+ prev = ++slash;
}
- g_snprintf(str, size, _("Browse: %s%s%s"),
- parentdir ? parentdir : "",
- parentdir ? "/" : "",
- g_basename(browser.filelist->path));
- free(dirname);
- free(parentdir);
+ if (path == NULL)
+ /* fall back to full path */
+ path = browser.filelist->path;
+
+ g_snprintf(str, size, _("Browse: %s"), path);
return str;
}