comparison src/ui_fileops.c @ 544:8de7cdde59dd

Simplify remove_extension_from_path().
author zas_
date Fri, 02 May 2008 20:40:47 +0000
parents b68fd1eb3243
children e421326e8b43
comparison
equal deleted inserted replaced
543:b68fd1eb3243 544:8de7cdde59dd
763 return (p > e && strncasecmp(path + p - e, ext, e) == 0); 763 return (p > e && strncasecmp(path + p - e, ext, e) == 0);
764 } 764 }
765 765
766 gchar *remove_extension_from_path(const gchar *path) 766 gchar *remove_extension_from_path(const gchar *path)
767 { 767 {
768 gchar *new_path; 768 gint p = 0, n = -1;
769 const gchar *ptr = path;
770 gint p;
771 769
772 if (!path) return NULL; 770 if (!path) return NULL;
773 if (strlen(path) < 2) return g_strdup(path); 771
774 772 while (path[p])
775 p = strlen(path) - 1; 773 {
776 while (ptr[p] != '.' && p > 0) p--; 774 if (path[p] == '.') n = p;
777 if (p == 0) p = strlen(path) - 1; 775 p++;
778 new_path = g_strndup(path, (guint)p); 776 }
779 return new_path; 777 if (n < 0) n = p;
778
779 return g_strndup(path, (gsize) n);
780 } 780 }
781 781
782 void parse_out_relatives(gchar *path) 782 void parse_out_relatives(gchar *path)
783 { 783 {
784 gint s, t; 784 gint s, t;