mirror of
https://github.com/swaywm/sway.git
synced 2026-04-26 06:46:26 -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 <string.h>
|
||||
#include <strings.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <wayland-server-protocol.h>
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
|
|
@ -142,3 +144,21 @@ bool sway_set_cloexec(int fd, bool cloexec) {
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue