Move append_path_save in util

Signed-off-by: Felix Weilbach <felix.weilbach@t-online.de>
This commit is contained in:
Felix Weilbach 2021-05-01 12:24:19 +02:00
parent 59d245cf5b
commit 402706ff9d
5 changed files with 25 additions and 21 deletions

View file

@ -10,6 +10,7 @@
#include <unistd.h>
#include <wordexp.h>
#include "swaybar/icon.h"
#include "util.h"
#include "config.h"
#include "list.h"
#include "log.h"
@ -24,24 +25,6 @@ static bool dir_exists(char *path) {
return stat(path, &sb) == 0 && S_ISDIR(sb.st_mode);
}
char* append_path_safe(const char * base_path, const char * append_path) {
assert(base_path);
assert(append_path);
size_t base_path_len = strlen(base_path);
if (base_path[base_path_len - 1] == '/') {
size_t path_len = snprintf(NULL, 0, "%s%s", base_path, append_path) + 1;
char *path = malloc(path_len);
snprintf(path, path_len, "%s%s", base_path, append_path);
return path;
}
size_t path_len = snprintf(NULL, 0, "%s/%s", base_path, append_path) + 1;
char *path = malloc(path_len);
snprintf(path, path_len, "%s/%s", base_path, append_path);
return path;
}
static list_t *get_basedirs(void) {
list_t *basedirs = create_list();
list_add(basedirs, strdup("$HOME/.icons")); // deprecated