A bit of refactoring
o9000 mrovi9000@gmail.com
2 files changed,
30 insertions(+),
15 deletions(-)
M
src/launcher/icon-theme-common.c
→
src/launcher/icon-theme-common.c
@@ -535,18 +535,33 @@ const IconThemeDir *db = (const IconThemeDir *)b;
return abs(da->size - size) - abs(db->size - size); } +Bool is_full_path(const char *s) +{ + if (!s) + return FALSE; + return s[0] == '/'; +} + +Bool file_exists(const char *path) +{ + return g_file_test(path, G_FILE_TEST_EXISTS); +} + +char *icon_path_from_full_path(const char *s) +{ + if (is_full_path(s) && file_exists(s)) + return strdup(s); + return NULL; +} + char *get_icon_path_helper(GSList *themes, const char *icon_name, int size) { - if (icon_name == NULL) + if (!icon_name) return NULL; - // If the icon_name is already a path and the file exists, return it - if (strstr(icon_name, "/") == icon_name) { - if (g_file_test(icon_name, G_FILE_TEST_EXISTS)) - return strdup(icon_name); - else - return NULL; - } + char *result = icon_path_from_full_path(icon_name); + if (result) + return result; const GSList *basenames = get_icon_locations(); GSList *extensions = NULL;@@ -679,10 +694,10 @@ for (const GSList *base = basenames; base; base = g_slist_next(base)) {
for (GSList *ext = extensions; ext; ext = g_slist_next(ext)) { char *base_name = (char *)base->data; char *extension = (char *)ext->data; - size_t file_name_size = strlen(base_name) + strlen(icon_name) + strlen(extension) + 100; - file_name = calloc(file_name_size, 1); + size_t file_name_size2 = strlen(base_name) + strlen(icon_name) + strlen(extension) + 100; + file_name = calloc(file_name_size2, 1); // filename = directory/iconname.extension - snprintf(file_name, file_name_size, "%s/%s%s", base_name, icon_name, extension); + snprintf(file_name, file_name_size2, "%s/%s%s", base_name, icon_name, extension); if (debug_icons) fprintf(stderr, "tint2: Checking %s\n", file_name); if (g_file_test(file_name, G_FILE_TEST_EXISTS)) {
M
src/util/common.c
→
src/util/common.c
@@ -483,10 +483,10 @@ strlcat(home_slash, home, buf_size);
strlcat(home_slash, "/", buf_size); if ((strcmp(s, home) == 0 || strstr(s, home_slash) == s)) { - size_t buf_size = strlen(s) - strlen(home) + 2; - char *result = calloc(buf_size, 1); - strlcat(result, "~", buf_size); - strlcat(result, s + strlen(home), buf_size); + size_t buf_size2 = strlen(s) - strlen(home) + 2; + char *result = calloc(buf_size2, 1); + strlcat(result, "~", buf_size2); + strlcat(result, s + strlen(home), buf_size2); free(home_slash); return result; } else {