From 1af3d14f3f995645a0de08a54b244c19840709e9 Mon Sep 17 00:00:00 2001 From: Hannes Schulze Date: Thu, 19 Jun 2025 23:17:58 +0200 Subject: init hs project --- csrc/utils.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 csrc/utils.c (limited to 'csrc/utils.c') diff --git a/csrc/utils.c b/csrc/utils.c new file mode 100644 index 0000000..dae3e65 --- /dev/null +++ b/csrc/utils.c @@ -0,0 +1,25 @@ +#include "utils.h" +#include + +// +// 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 ); +} -- cgit v1.3.1