aboutsummaryrefslogtreecommitdiff
path: root/analyzer/utils/fs.c
diff options
context:
space:
mode:
authorMaciej Borowiec <81316152+Mosder@users.noreply.github.com>2026-06-14 01:54:07 +0200
committerGitHub <noreply@github.com>2026-06-14 01:54:07 +0200
commit2e3f7fe39791cd671a68330f7ba7a5bb5fc6f9ae (patch)
treebf2f679387bff19637e1183400c0b0290d2d1834 /analyzer/utils/fs.c
parent35dc15a03ba5cf2dec10d63a1fdc7ab1fb082899 (diff)
parentc2568d72efca8fae3c610072cb055f9c8de3ca5f (diff)
Merge pull request #4 from Mosder/2-simple-capturing-mode
Simple capturing mode
Diffstat (limited to 'analyzer/utils/fs.c')
-rw-r--r--analyzer/utils/fs.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/analyzer/utils/fs.c b/analyzer/utils/fs.c
new file mode 100644
index 0000000..76fb581
--- /dev/null
+++ b/analyzer/utils/fs.c
@@ -0,0 +1,43 @@
+#include "utils.h"
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+void get_home_dir(char *home_dir) {
+ strcpy(home_dir, getenv("HOME"));
+}
+
+void get_main_dir(char *main_dir) {
+ char home_dir[256];
+ get_home_dir(home_dir);
+ sprintf(main_dir, "%s/.local/share/branal", home_dir);
+}
+
+void get_capture_dir(char *capture_dir) {
+ char main_dir[256];
+ get_main_dir(main_dir);
+ sprintf(capture_dir, "%s/captures", main_dir);
+}
+
+void get_saves_dir(char *saves_dir) {
+ char main_dir[256];
+ get_main_dir(main_dir);
+ sprintf(saves_dir, "%s/saves", main_dir);
+}
+
+void create_necessary_directories() {
+ char main_dir[256], capture_dir[256], saves_dir[256];
+ get_main_dir(main_dir);
+ get_capture_dir(capture_dir);
+ get_saves_dir(saves_dir);
+ mkdir(main_dir, 0755);
+ mkdir(capture_dir, 0755);
+ mkdir(saves_dir, 0755);
+}
+
+void write_file(char *path, void *contents, int contents_len, int flags, mode_t permissions) {
+ int fd = open(path, flags, permissions);
+ write(fd, contents, contents_len);
+ close(fd);
+}