summaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorHannes Schulze <haschu0103@outlook.de>2024-05-06 13:42:55 +0200
committerHannes Schulze <haschu0103@outlook.de>2024-05-06 14:33:54 +0200
commit37d5ef75306c45ca95550f4af40d9750c5b9cb88 (patch)
tree7125c8e8445eeecb86097bc99bb2d1febfb7e2a5 /src/utils.c
initial commit
yup, i definitely wrote all of this in a single commit
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
new file mode 100644
index 0000000..af1a3c7
--- /dev/null
+++ b/src/utils.c
@@ -0,0 +1,25 @@
+#include "utils.h"
+#include <gio/gio.h>
+
+//
+// Return the path for a file in the user's XDG cache directory. The result should be freed using g_free.
+//
+// This will also ensure that the application's cache directory exists.
+//
+gchar* foobar_get_cache_path( gchar const* filename )
+{
+ g_autoptr( GError ) error = NULL;
+ g_autofree gchar* directory_path = g_strdup_printf( "%s/foobar", g_get_user_cache_dir( ) );
+
+ if ( !g_file_test( directory_path, G_FILE_TEST_EXISTS ) )
+ {
+ g_autoptr( GFile ) cache_dir = g_file_new_for_path( directory_path );
+ if ( !g_file_make_directory_with_parents( cache_dir, NULL, &error ) )
+ {
+ g_warning( "Unable to create cache directory: %s", error->message );
+ return NULL;
+ }
+ }
+
+ return g_strdup_printf( "%s/%s", directory_path, filename );
+} \ No newline at end of file