From 048b8d21ecbd1168ff8e033b12cbfd66bba0127c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 15 Jul 2024 18:57:33 +0200 Subject: Add support for desktop portal capture (-w portal) --- src/utils.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index e00f3c5..d768f58 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,13 +1,19 @@ #include "../include/utils.h" + #include #include #include #include #include +#include +#include +#include + #include #include -#include + #include +#include double clock_get_monotonic_seconds(void) { struct timespec ts; @@ -480,3 +486,35 @@ bool gsr_card_path_get_render_path(const char *card_path, char *render_path) { close(fd); return false; } + +int create_directory_recursive(char *path) { + int path_len = strlen(path); + char *p = path; + char *end = path + path_len; + for(;;) { + char *slash_p = strchr(p, '/'); + + // Skips first '/', we don't want to try and create the root directory + if(slash_p == path) { + ++p; + continue; + } + + if(!slash_p) + slash_p = end; + + char prev_char = *slash_p; + *slash_p = '\0'; + int err = mkdir(path, S_IRWXU); + *slash_p = prev_char; + + if(err == -1 && errno != EEXIST) + return err; + + if(slash_p == end) + break; + else + p = slash_p + 1; + } + return 0; +} -- cgit v1.2.3