about summary refs log tree commit diff stats
path: root/src/config/files.c
diff options
context:
space:
mode:
authorSteffen Jaeckel <jaeckel-floss@eyet-services.de>2022-03-13 11:58:56 +0100
committerSteffen Jaeckel <jaeckel-floss@eyet-services.de>2022-03-13 14:15:02 +0100
commitb8e46552bffc559263e86b2dcc0331b3f47065b7 (patch)
treeedd714bd6487ae39a3d6b7c77f799391b5071151 /src/config/files.c
parent764a7fb71b6cc401ed77233bbcd4d67201f9ca85 (diff)
downloadprofani-tty-b8e46552bffc559263e86b2dcc0331b3f47065b7.tar.gz
add `files_file_in_account_data_path()`
As all parts of the code invoking the `files_get_account_data_path()`
function did the same afterwards, a function has been added with the same
behavior.

1. create path
2. `mkdir` of that path
3. return final path

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
Diffstat (limited to 'src/config/files.c')
-rw-r--r--src/config/files.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/config/files.c b/src/config/files.c
index ce3f1196..8a241be5 100644
--- a/src/config/files.c
+++ b/src/config/files.c
@@ -38,6 +38,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
 #include <glib.h>
 
 #include "common.h"
@@ -191,6 +193,25 @@ files_get_account_data_path(const char* const specific_dir, const char* const ji
     return result;
 }
 
+gchar*
+files_file_in_account_data_path(const char* const specific_dir, const char* const jid, const char* const file_name)
+{
+    gchar* data_path = files_get_account_data_path(specific_dir, jid);
+
+    if (g_mkdir_with_parents(data_path, S_IRWXU) != 0) {
+        log_error("Failed to create directory at '%s' with error '%s'", data_path, strerror(errno));
+        g_free(data_path);
+        return NULL;
+    }
+
+    if (!file_name) {
+        return data_path;
+    }
+    gchar* filename = g_strdup_printf("%s/%s", data_path, file_name);
+    g_free(data_path);
+    return filename;
+}
+
 static char*
 _files_get_xdg_config_home(void)
 {