aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2005-02-28 02:50:45 +0800
committerChristian Persch <chpe@src.gnome.org>2005-02-28 02:50:45 +0800
commit22e053c43179e739314ac9771932e1394ad91387 (patch)
treefb267e0296a4fcc7c3d9f71bcd1dfb44bf2342d5 /lib
parentd8c89be1293cf71ee242f812b3c4552c3f5e8c66 (diff)
downloadgsoc2013-epiphany-22e053c43179e739314ac9771932e1394ad91387.tar
gsoc2013-epiphany-22e053c43179e739314ac9771932e1394ad91387.tar.gz
gsoc2013-epiphany-22e053c43179e739314ac9771932e1394ad91387.tar.bz2
gsoc2013-epiphany-22e053c43179e739314ac9771932e1394ad91387.tar.lz
gsoc2013-epiphany-22e053c43179e739314ac9771932e1394ad91387.tar.xz
gsoc2013-epiphany-22e053c43179e739314ac9771932e1394ad91387.tar.zst
gsoc2013-epiphany-22e053c43179e739314ac9771932e1394ad91387.zip
Fix compress_tilde to only look at the prefix, and not substitute in the
2005-02-27 Christian Persch <chpe@cvs.gnome.org> * lib/eel-gconf-extensions.c: (tilde_compress): Fix compress_tilde to only look at the prefix, and not substitute in the middle.
Diffstat (limited to 'lib')
-rw-r--r--lib/eel-gconf-extensions.c46
1 files changed, 9 insertions, 37 deletions
diff --git a/lib/eel-gconf-extensions.c b/lib/eel-gconf-extensions.c
index 7f616084d..432b0d693 100644
--- a/lib/eel-gconf-extensions.c
+++ b/lib/eel-gconf-extensions.c
@@ -670,47 +670,19 @@ eel_gconf_get_float (const char *key)
static char *
tilde_compress (const char *path)
{
- const char *home_dir = g_get_home_dir();
- int home_dir_l = strlen (home_dir);
- int ntilde = 0;
- const char *scan;
- int path_l, result_l;
- char *result, *scan2;
-
- if (path == NULL)
- return NULL;
+ const char *home;
- path_l = strlen (path);
- for (scan = path; scan != NULL; scan++) {
- if (path_l - (scan - path) < home_dir_l)
- break;
- if (strncmp (scan, home_dir, home_dir_l) == 0)
- ntilde++;
- }
-
- if (ntilde == 0)
- return g_strdup (path);
-
- result_l = strlen (path) + ntilde - (ntilde * home_dir_l);
- result = g_new (char, result_l + 1);
+ if (path == NULL) return NULL;
- for (scan = path, scan2 = result; scan != NULL; scan2++) {
- if (path_l - (scan - path) < home_dir_l) {
- strcpy (scan2, scan);
- scan2 += strlen (scan);
- break;
- }
- if (strncmp (scan, home_dir, home_dir_l) == 0) {
- *scan2 = '~';
- scan += home_dir_l;
- } else {
- *scan2 = *scan;
- scan++;
- }
+ home = g_get_home_dir ();
+ if (home == NULL) return g_strdup (path);
+
+ if (g_str_has_prefix (path, home))
+ {
+ return g_strconcat ("~", path + strlen (home), NULL);
}
- *scan2 = 0;
- return result;
+ return g_strdup (path);
}
void