From 153e84c8b84dbc9f414eedcbc79dd2214d8d9d4d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 7 Jul 2021 15:53:05 +1000 Subject: [PATCH] lib: always return the full path from wp_get_config/data_dir Remove the need for the caller to check if the returned path is absolute or relative. --- lib/wp/wp.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/wp/wp.c b/lib/wp/wp.c index 78d01c80..28c77358 100644 --- a/lib/wp/wp.c +++ b/lib/wp/wp.c @@ -114,33 +114,41 @@ wp_get_xdg_config_dir (void) } /*! - * \brief Gets the Wireplumber configuration directory + * \brief Gets the full path to the Wireplumber configuration directory * \returns The Wireplumber configuration directory */ const gchar * wp_get_config_dir (void) { - static const gchar *config_dir = NULL; - if (!config_dir) { - config_dir = g_getenv ("WIREPLUMBER_CONFIG_DIR"); - if (!config_dir) - config_dir = WIREPLUMBER_DEFAULT_CONFIG_DIR; + static gchar config_dir[PATH_MAX] = {0}; + if (config_dir[0] == '\0') { + g_autofree gchar *abspath; + const gchar *path = g_getenv ("WIREPLUMBER_CONFIG_DIR"); + + if (!path) + path = WIREPLUMBER_DEFAULT_CONFIG_DIR; + + abspath = g_canonicalize_filename (path, NULL); + g_strlcpy (config_dir, abspath, sizeof (config_dir)); } return config_dir; } /*! - * \brief Gets the Wireplumber data directory + * \brief Gets full path to the Wireplumber data directory * \returns The Wireplumber data directory */ const gchar * wp_get_data_dir (void) { - static const gchar *data_dir = NULL; - if (!data_dir) { - data_dir = g_getenv ("WIREPLUMBER_DATA_DIR"); - if (!data_dir) - data_dir = WIREPLUMBER_DEFAULT_DATA_DIR; + static gchar data_dir[PATH_MAX] = {0}; + if (data_dir[0] == '\0') { + g_autofree gchar *abspath; + const char *path = g_getenv ("WIREPLUMBER_DATA_DIR"); + if (!path) + path = WIREPLUMBER_DEFAULT_DATA_DIR; + abspath = g_canonicalize_filename (path, NULL); + g_strlcpy (data_dir, abspath, sizeof (data_dir)); } return data_dir; }