From 22e053c43179e739314ac9771932e1394ad91387 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sun, 27 Feb 2005 18:50:45 +0000 Subject: Fix compress_tilde to only look at the prefix, and not substitute in the 2005-02-27 Christian Persch * lib/eel-gconf-extensions.c: (tilde_compress): Fix compress_tilde to only look at the prefix, and not substitute in the middle. --- ChangeLog | 7 +++++++ embed/mozilla/MozDownload.cpp | 2 +- lib/eel-gconf-extensions.c | 46 +++++++++---------------------------------- 3 files changed, 17 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index f999e1c27..56f0a942b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-02-27 Christian Persch + + * lib/eel-gconf-extensions.c: (tilde_compress): + + Fix compress_tilde to only look at the prefix, and not + substitute in the middle. + 2005-02-27 Christian Persch * embed/mozilla/MozDownload.cpp: diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp index 248286ff1..419123c76 100644 --- a/embed/mozilla/MozDownload.cpp +++ b/embed/mozilla/MozDownload.cpp @@ -380,7 +380,7 @@ MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsEmbedCString cDesc; NS_UTF16ToCString (description, NS_CSTRING_ENCODING_UTF8, cDesc); #else - char *mime; + char *mime = nsnull; rv = mMIMEInfo->GetMIMEType (&mime); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); 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 -- cgit v1.2.3