aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-07-15 18:57:33 +0200
committerdec05eba <dec05eba@protonmail.com>2024-07-15 19:02:34 +0200
commit048b8d21ecbd1168ff8e033b12cbfd66bba0127c (patch)
treef536c35090a6ed78803d064c0784370a2424ca7a /src/utils.c
parentc447a9a35f51815db307e5d58630040cd63ad4b7 (diff)
Add support for desktop portal capture (-w portal)
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c40
1 files changed, 39 insertions, 1 deletions
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 <time.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <errno.h>
+
#include <xf86drmMode.h>
#include <xf86drm.h>
-#include <stdlib.h>
+
#include <X11/Xatom.h>
+#include <X11/extensions/Xrandr.h>
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;
+}