diff options
Diffstat (limited to 'swaybar/tray/icon.c')
-rw-r--r-- | swaybar/tray/icon.c | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/swaybar/tray/icon.c b/swaybar/tray/icon.c index c426c3d4..b513dca5 100644 --- a/swaybar/tray/icon.c +++ b/swaybar/tray/icon.c | |||
@@ -40,9 +40,7 @@ static list_t *get_basedirs(void) { | |||
40 | data_dirs = strdup(data_dirs); | 40 | data_dirs = strdup(data_dirs); |
41 | char *dir = strtok(data_dirs, ":"); | 41 | char *dir = strtok(data_dirs, ":"); |
42 | do { | 42 | do { |
43 | size_t path_len = snprintf(NULL, 0, "%s/icons", dir) + 1; | 43 | char *path = format_str("%s/icons", dir); |
44 | char *path = malloc(path_len); | ||
45 | snprintf(path, path_len, "%s/icons", dir); | ||
46 | list_add(basedirs, path); | 44 | list_add(basedirs, path); |
47 | } while ((dir = strtok(NULL, ":"))); | 45 | } while ((dir = strtok(NULL, ":"))); |
48 | free(data_dirs); | 46 | free(data_dirs); |
@@ -206,13 +204,7 @@ static const char *entry_handler(char *group, char *key, char *value, | |||
206 | */ | 204 | */ |
207 | static struct icon_theme *read_theme_file(char *basedir, char *theme_name) { | 205 | static struct icon_theme *read_theme_file(char *basedir, char *theme_name) { |
208 | // look for index.theme file | 206 | // look for index.theme file |
209 | size_t path_len = snprintf(NULL, 0, "%s/%s/index.theme", basedir, | 207 | char *path = format_str("%s/%s/index.theme", basedir, theme_name); |
210 | theme_name) + 1; | ||
211 | char *path = malloc(path_len); | ||
212 | if (!path) { | ||
213 | return NULL; | ||
214 | } | ||
215 | snprintf(path, path_len, "%s/%s/index.theme", basedir, theme_name); | ||
216 | FILE *theme_file = fopen(path, "r"); | 208 | FILE *theme_file = fopen(path, "r"); |
217 | free(path); | 209 | free(path); |
218 | if (!theme_file) { | 210 | if (!theme_file) { |
@@ -416,26 +408,20 @@ static char *find_icon_in_subdir(char *name, char *basedir, char *theme, | |||
416 | #endif | 408 | #endif |
417 | }; | 409 | }; |
418 | 410 | ||
419 | size_t path_len = snprintf(NULL, 0, "%s/%s/%s/%s.EXT", basedir, theme, | ||
420 | subdir, name) + 1; | ||
421 | char *path = malloc(path_len); | ||
422 | |||
423 | for (size_t i = 0; i < sizeof(extensions) / sizeof(*extensions); ++i) { | 411 | for (size_t i = 0; i < sizeof(extensions) / sizeof(*extensions); ++i) { |
424 | snprintf(path, path_len, "%s/%s/%s/%s.%s", basedir, theme, subdir, | 412 | char *path = format_str("%s/%s/%s/%s.%s", |
425 | name, extensions[i]); | 413 | basedir, theme, subdir, name, extensions[i]); |
426 | if (access(path, R_OK) == 0) { | 414 | if (access(path, R_OK) == 0) { |
427 | return path; | 415 | return path; |
428 | } | 416 | } |
417 | free(path); | ||
429 | } | 418 | } |
430 | 419 | ||
431 | free(path); | ||
432 | return NULL; | 420 | return NULL; |
433 | } | 421 | } |
434 | 422 | ||
435 | static bool theme_exists_in_basedir(char *theme, char *basedir) { | 423 | static bool theme_exists_in_basedir(char *theme, char *basedir) { |
436 | size_t path_len = snprintf(NULL, 0, "%s/%s", basedir, theme) + 1; | 424 | char *path = format_str("%s/%s", basedir, theme); |
437 | char *path = malloc(path_len); | ||
438 | snprintf(path, path_len, "%s/%s", basedir, theme); | ||
439 | bool ret = dir_exists(path); | 425 | bool ret = dir_exists(path); |
440 | free(path); | 426 | free(path); |
441 | return ret; | 427 | return ret; |