[goobox] fixed cppcheck warning



commit e1130badc739570e50726234405e4831c4e22b7b
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Jan 4 18:34:05 2011 +0100

    fixed cppcheck warning
    
    use g_get_user_special_dir instead of a custom implementation

 src/glib-utils.c |  129 +----------------------------------------------------
 src/glib-utils.h |    1 -
 2 files changed, 3 insertions(+), 127 deletions(-)
---
diff --git a/src/glib-utils.c b/src/glib-utils.c
index dc4e2b1..095e957 100644
--- a/src/glib-utils.c
+++ b/src/glib-utils.c
@@ -1152,139 +1152,16 @@ get_desktop_uri (void)
 	static char *desktop_uri = NULL;
 
 	if (desktop_uri == NULL) {
-		char *path;
-		char *uri;
-
-		path = xdg_user_dir_lookup ("DESKTOP");
-		uri = g_uri_escape_string (path, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE);
-
-		desktop_uri = g_strconcat ("file://", uri, NULL);
+		const char *path;
 
-		g_free (uri);
-		g_free (path);
+		path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
+		desktop_uri = g_filename_to_uri (path, NULL, NULL);
 	}
 
 	return desktop_uri;
 }
 
 
-char *
-xdg_user_dir_lookup (const char *type)
-{
-	/* This function is used by gthumb to determine the default "PICTURES"
-	   directory for imports. The actually directory name is localized.
-	   Bug 425365. */
-
-	FILE *file;
-	char *home_dir, *config_home, *config_file;
-	char buffer[512];
-	char *user_dir;
-	char *p, *d;
-	int len;
-	int relative;
-
-	home_dir = getenv ("HOME");
-	if (home_dir == NULL)
-		return strdup ("/tmp");
-
-	config_home = getenv ("XDG_CONFIG_HOME");
-	if (config_home == NULL || config_home[0] == 0) {
-		config_file = malloc (strlen (home_dir) + strlen ("/.config/user-dirs.dirs") + 1);
-		strcpy (config_file, home_dir);
-		strcat (config_file, "/.config/user-dirs.dirs");
-	}
-	else {
-		config_file = malloc (strlen (config_home) + strlen ("/user-dirs.dirs") + 1);
-		strcpy (config_file, config_home);
-		strcat (config_file, "/user-dirs.dirs");
-	}
-
-	file = fopen (config_file, "r");
-	free (config_file);
-	if (file == NULL)
-		goto error;
-
-	user_dir = NULL;
-
-	while (fgets (buffer, sizeof (buffer), file)) {
-		/* Remove newline at end */
-		len = strlen (buffer);
-		if (len > 0 && buffer[len-1] == '\n')
-		buffer[len-1] = 0;
-
-		p = buffer;
-		while (*p == ' ' || *p == '\t')
-			p++;
-
-		if (strncmp (p, "XDG_", 4) != 0)
-			continue;
-		p += 4;
-
-		if (strncmp (p, type, strlen (type)) != 0)
-			continue;
-		p += strlen (type);
-
-		if (strncmp (p, "_DIR", 4) != 0)
-		continue;
-		p += 4;
-
-		while (*p == ' ' || *p == '\t')
-			p++;
-
-		if (*p != '=')
-			continue;
-		p++;
-
-		while (*p == ' ' || *p == '\t')
-			p++;
-
-		if (*p != '"')
-			continue;
-		p++;
-
-		relative = 0;
-		if (strncmp (p, "$HOME/", 6) == 0) {
-			p += 6;
-			relative = 1;
-		} else if (*p != '/')
-			continue;
-
-		if (relative) {
-			user_dir = malloc (strlen (home_dir) + 1 + strlen (p) + 1);
-			strcpy (user_dir, home_dir);
-			strcat (user_dir, "/");
-		} else {
-			user_dir = malloc (strlen (p) + 1);
-			*user_dir = 0;
-		}
-
-		d = user_dir + strlen (user_dir);
-		while (*p && *p != '"')	{
-			if ((*p == '\\') && (*(p+1) != 0))
-				p++;
-			*d++ = *p++;
-		}
-		*d = 0;
-	}
-
-	fclose (file);
-
-	if (user_dir)
-		return user_dir;
-
-error:
-	 /* Special case desktop for historical compatibility */
-	if (strcmp (type, "DESKTOP") == 0) {
-		user_dir = malloc (strlen (home_dir) + strlen ("/Desktop") + 1);
-		strcpy (user_dir, home_dir);
-		strcat (user_dir, "/Desktop");
-		return user_dir;
-	}
-	else
-		return strdup (home_dir);
-}
-
-
 int
 uricmp (const char *uri1,
 	const char *uri2)
diff --git a/src/glib-utils.h b/src/glib-utils.h
index 7377420..ea6c4a4 100644
--- a/src/glib-utils.h
+++ b/src/glib-utils.h
@@ -191,7 +191,6 @@ void            free_regexps                     (GRegex     **regexps);
 
 const char *    get_home_uri                     (void);
 const char *    get_desktop_uri                  (void);
-char *          xdg_user_dir_lookup              (const char *type);
 int             uricmp                           (const char *uri1,
 						  const char *uri2);
 gboolean        same_uri                         (const char *uri1,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]