mirror of
https://github.com/swaywm/sway.git
synced 2026-04-25 06:46:24 -04:00
Move append_path_save in util
Signed-off-by: Felix Weilbach <felix.weilbach@t-online.de>
This commit is contained in:
parent
59d245cf5b
commit
402706ff9d
5 changed files with 25 additions and 21 deletions
|
|
@ -6,6 +6,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <wayland-server-protocol.h>
|
#include <wayland-server-protocol.h>
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
@ -142,3 +144,21 @@ bool sway_set_cloexec(int fd, bool cloexec) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,6 @@ struct icon_theme {
|
||||||
void init_themes(list_t **themes, list_t **basedirs);
|
void init_themes(list_t **themes, list_t **basedirs);
|
||||||
void finish_themes(list_t *themes, list_t *basedirs);
|
void finish_themes(list_t *themes, list_t *basedirs);
|
||||||
|
|
||||||
char *append_path_safe(const char *base_path, const char *append_path);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Finds an icon of a specified size given a list of themes and base directories.
|
* Finds an icon of a specified size given a list of themes and base directories.
|
||||||
* If the icon is found, the pointers min_size & max_size are set to minimum &
|
* If the icon is found, the pointers min_size & max_size are set to minimum &
|
||||||
|
|
|
||||||
|
|
@ -67,4 +67,6 @@ const char *sway_wl_output_subpixel_to_string(enum wl_output_subpixel subpixel);
|
||||||
|
|
||||||
bool sway_set_cloexec(int fd, bool cloexec);
|
bool sway_set_cloexec(int fd, bool cloexec);
|
||||||
|
|
||||||
|
char *append_path_safe(const char *base_path, const char *append_path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#define _POSIX_C_SOURCE 200809
|
#define _POSIX_C_SOURCE 200809L
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include "swaybar/icon.h"
|
#include "swaybar/icon.h"
|
||||||
#include "desktop.h"
|
#include "desktop.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
static list_t *get_desktop_files_basedirs() {
|
static list_t *get_desktop_files_basedirs() {
|
||||||
list_t *basedirs = create_list();
|
list_t *basedirs = create_list();
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wordexp.h>
|
#include <wordexp.h>
|
||||||
#include "swaybar/icon.h"
|
#include "swaybar/icon.h"
|
||||||
|
#include "util.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
@ -24,24 +25,6 @@ static bool dir_exists(char *path) {
|
||||||
return stat(path, &sb) == 0 && S_ISDIR(sb.st_mode);
|
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) {
|
static list_t *get_basedirs(void) {
|
||||||
list_t *basedirs = create_list();
|
list_t *basedirs = create_list();
|
||||||
list_add(basedirs, strdup("$HOME/.icons")); // deprecated
|
list_add(basedirs, strdup("$HOME/.icons")); // deprecated
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue