Mercurial > hg > forks > geeqie
changeset 260:9252d2fcaf51
Improve remove_trailing_slash() so it allocates no more than
needed bytes and remove all trailing slashes instead only one.
author | Laurent Monin <geeqie@norz.org> |
---|---|
date | Sat, 05 Apr 2008 15:23:39 +0000 |
parents | ef0212c6e59f |
children | 37854c69a44f |
files | src/ui_tabcomp.c |
diffstat | 1 files changed, 4 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ui_tabcomp.c Sat Apr 05 11:59:29 2008 +0000 +++ b/src/ui_tabcomp.c Sat Apr 05 15:23:39 2008 +0000 @@ -814,15 +814,14 @@ gchar *remove_trailing_slash(const gchar *path) { - gchar *ret; gint l; + if (!path) return NULL; - ret = g_strdup(path); - l = strlen(ret); - if (l > 1 && ret[l - 1] == '/') ret[l - 1] = '\0'; + l = strlen(path); + while (l > 1 && path[l - 1] == '/') l--; - return ret; + return g_strndup(path, l); } static void tab_completion_select_cancel_cb(FileDialog *fd, gpointer data)