Simplify remove_extension_from_path().
authorLaurent Monin <geeqie@norz.org>
Fri, 2 May 2008 20:40:47 +0000 (20:40 +0000)
committerLaurent Monin <geeqie@norz.org>
Fri, 2 May 2008 20:40:47 +0000 (20:40 +0000)
src/ui_fileops.c

index 2a028fa..f6b8ef9 100644 (file)
@@ -765,18 +765,18 @@ gint file_extension_match(const gchar *path, const gchar *ext)
 
 gchar *remove_extension_from_path(const gchar *path)
 {
-       gchar *new_path;
-       const gchar *ptr = path;
-       gint p;
+       gint p = 0, n = -1;
 
        if (!path) return NULL;
-       if (strlen(path) < 2) return g_strdup(path);
 
-       p = strlen(path) - 1;
-       while (ptr[p] != '.' && p > 0) p--;
-       if (p == 0) p = strlen(path) - 1;
-       new_path = g_strndup(path, (guint)p);
-       return new_path;
+       while (path[p])
+               {
+               if (path[p] == '.') n = p;
+               p++;
+               }
+       if (n < 0) n = p;
+
+       return g_strndup(path, (gsize) n);
 }
 
 void parse_out_relatives(gchar *path)