# HG changeset patch
# Node ID 9c74f2514652
# Parent  02bef3334429
diff --git a/libpurple/buddyicon.c b/libpurple/buddyicon.c
--- a/libpurple/buddyicon.c
+++ b/libpurple/buddyicon.c
@@ -26,9 +26,9 @@
 #include "purpleaccountmanager.h"
 #include "purpleconversation.h"
 #include "purpleconversationmanager.h"
+#include "purplepath.h"
 #include "purpleprivate.h"
 #include "purpleprotocolserver.h"
-#include "util.h"
 
 /* NOTE: Instances of this struct are allocated without zeroing the memory, so
  * NOTE: be sure to update purple_buddy_icon_new() if you add members. */
diff --git a/libpurple/core.c b/libpurple/core.c
--- a/libpurple/core.c
+++ b/libpurple/core.c
@@ -39,6 +39,7 @@
 #include "purplecredentialmanager.h"
 #include "purplehistorymanager.h"
 #include "purplemessage.h"
+#include "purplepath.h"
 #include "purpleprivate.h"
 #include "savedstatuses.h"
 #include "signals.h"
diff --git a/libpurple/media/backend-fs2.c b/libpurple/media/backend-fs2.c
--- a/libpurple/media/backend-fs2.c
+++ b/libpurple/media/backend-fs2.c
@@ -30,7 +30,8 @@
 #include "debug.h"
 #include "network.h"
 #include "media-gst.h"
-#include <purplekeyvaluepair.h>
+#include <libpurple/purplepath.h>
+#include <libpurple/purplekeyvaluepair.h>
 
 /* Ignore deprecations of GParameter in FarStream's headers. */
 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
diff --git a/libpurple/mediamanager.c b/libpurple/mediamanager.c
--- a/libpurple/mediamanager.c
+++ b/libpurple/mediamanager.c
@@ -28,6 +28,7 @@
 #include "glibcompat.h"
 #include "media.h"
 #include "mediamanager.h"
+#include "purplepath.h"
 
 #include "media-gst.h"
 #include <media/backend-fs2.h>
diff --git a/libpurple/meson.build b/libpurple/meson.build
--- a/libpurple/meson.build
+++ b/libpurple/meson.build
@@ -61,6 +61,7 @@
 	'purplemessage.c',
 	'purplenoopcredentialprovider.c',
 	'purpleoptions.c',
+	'purplepath.c',
 	'purpleplugininfo.c',
 	'purplepresence.c',
 	'purpleprotocol.c',
@@ -153,6 +154,7 @@
 	'purplemessage.h',
 	'purplenoopcredentialprovider.h',
 	'purpleoptions.h',
+	'purplepath.h',
 	'purpleplugininfo.h',
 	'purplepresence.h',
 	'purpleprotocol.h',
diff --git a/libpurple/prefs.c b/libpurple/prefs.c
--- a/libpurple/prefs.c
+++ b/libpurple/prefs.c
@@ -32,6 +32,7 @@
 
 #include "prefs.h"
 #include "debug.h"
+#include "purplepath.h"
 #include "util.h"
 
 static PurplePrefsUiOps *prefs_ui_ops = NULL;
diff --git a/libpurple/purplepath.h b/libpurple/purplepath.h
new file mode 100644
--- /dev/null
+++ b/libpurple/purplepath.h
@@ -0,0 +1,103 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#if !defined(PURPLE_GLOBAL_HEADER_INSIDE) && !defined(PURPLE_COMPILATION)
+# error "only <purple.h> may be included directly"
+#endif
+
+#ifndef PURPLE_PATH_H
+#define PURPLE_PATH_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+/**
+ * purple_home_dir:
+ *
+ * Returns the user's home directory.
+ *
+ *  See purple_user_dir()
+ *
+ * Returns: The user's home directory.
+ */
+const gchar *purple_home_dir(void);
+
+/**
+ * purple_user_dir:
+ *
+ * Returns the purple settings directory in the user's home directory.
+ * This is usually $HOME/.purple
+ *
+ *  See purple_home_dir()
+ *
+ * Returns: The purple settings directory.
+ *
+ * Deprecated: Use purple_cache_dir(), purple_config_dir() or
+ *             purple_data_dir() instead.
+ */
+G_DEPRECATED_FOR(purple_cache_dir or purple_config_dir or purple_data_dir)
+const gchar *purple_user_dir(void);
+
+/**
+ * purple_cache_dir:
+ *
+ * Returns the purple cache directory according to XDG Base Directory Specification.
+ * This is usually $HOME/.cache/purple.
+ * If custom user dir was specified then this is cache
+ * sub-directory of DIR argument passed to -c option.
+ *
+ * Returns: The purple cache directory.
+ */
+const gchar *purple_cache_dir(void);
+
+/**
+ * purple_config_dir:
+ *
+ * Returns the purple configuration directory according to XDG Base Directory Specification.
+ * This is usually $HOME/.config/purple.
+ * If custom user dir was specified then this is config
+ * sub-directory of DIR argument passed to -c option.
+ *
+ * Returns: The purple configuration directory.
+ */
+const gchar *purple_config_dir(void);
+
+/**
+ * purple_data_dir:
+ *
+ * Returns the purple data directory according to XDG Base Directory Specification.
+ * This is usually $HOME/.local/share/purple.
+ * If custom user dir was specified then this is data
+ * sub-directory of DIR argument passed to -c option.
+ *
+ * Returns: The purple data directory.
+ */
+const gchar *purple_data_dir(void);
+
+/**
+ * purple_util_set_user_dir:
+ * @dir: The custom settings directory
+ *
+ * Define a custom purple settings directory, overriding the default (user's home directory/.purple)
+ */
+void purple_util_set_user_dir(const gchar *dir);
+
+G_END_DECLS
+
+#endif /* PURPLE_PATH_H */
diff --git a/libpurple/purplepath.c b/libpurple/purplepath.c
new file mode 100644
--- /dev/null
+++ b/libpurple/purplepath.c
@@ -0,0 +1,101 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <libpurple/purplepath.h>
+
+/******************************************************************************
+ * Globals
+ *****************************************************************************/
+static gchar *custom_user_dir = NULL;
+static gchar *user_dir = NULL;
+static gchar *cache_dir = NULL;
+static gchar *config_dir = NULL;
+static gchar *data_dir = NULL;
+
+/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+static const gchar *
+purple_xdg_dir(gchar **xdg_dir, const gchar *xdg_base_dir,
+               const gchar *xdg_type)
+{
+	if (!*xdg_dir) {
+		if (!custom_user_dir) {
+			*xdg_dir = g_build_filename(xdg_base_dir, "purple", NULL);
+		} else {
+			*xdg_dir = g_build_filename(custom_user_dir, xdg_type, NULL);
+		}
+	}
+
+	return *xdg_dir;
+}
+
+/******************************************************************************
+ * Public API
+ *****************************************************************************/
+const gchar *
+purple_home_dir(void) {
+#ifndef _WIN32
+	return g_get_home_dir();
+#else
+	return wpurple_home_dir();
+#endif
+}
+
+/* Returns the argument passed to -c IFF it was present, or ~/.purple. */
+const gchar *
+purple_user_dir(void) {
+	if(custom_user_dir != NULL) {
+		return custom_user_dir;
+	} else if(!user_dir) {
+		user_dir = g_build_filename(purple_home_dir(), ".purple", NULL);
+	}
+
+	return user_dir;
+}
+
+const gchar *
+purple_cache_dir(void) {
+	return purple_xdg_dir(&cache_dir, g_get_user_cache_dir(), "cache");
+}
+
+const gchar *
+purple_config_dir(void) {
+	return purple_xdg_dir(&config_dir, g_get_user_config_dir(), "config");
+}
+
+const gchar *
+purple_data_dir(void) {
+	return purple_xdg_dir(&data_dir, g_get_user_data_dir(), "data");
+}
+
+void
+purple_util_set_user_dir(const gchar *dir) {
+	g_free(custom_user_dir);
+
+	if(dir != NULL && *dir) {
+		custom_user_dir = g_strdup(dir);
+	} else {
+		custom_user_dir = NULL;
+	}
+
+	g_clear_pointer(&user_dir, g_free);
+	g_clear_pointer(&cache_dir, g_free);
+	g_clear_pointer(&config_dir, g_free);
+	g_clear_pointer(&data_dir, g_free);
+}
diff --git a/libpurple/util.h b/libpurple/util.h
--- a/libpurple/util.h
+++ b/libpurple/util.h
@@ -191,78 +191,6 @@
 /**************************************************************************/
 /* Path/Filename Functions                                                */
 /**************************************************************************/
-
-/**
- * purple_home_dir:
- *
- * Returns the user's home directory.
- *
- *  See purple_user_dir()
- *
- * Returns: The user's home directory.
- */
-const gchar *purple_home_dir(void);
-
-/**
- * purple_user_dir:
- *
- * Returns the purple settings directory in the user's home directory.
- * This is usually $HOME/.purple
- *
- *  See purple_home_dir()
- *
- * Returns: The purple settings directory.
- * 
- * Deprecated: Use purple_cache_dir(), purple_config_dir() or
- *             purple_data_dir() instead.
- */
-G_DEPRECATED_FOR(purple_cache_dir or purple_config_dir or purple_data_dir)
-const char *purple_user_dir(void);
-
-/**
- * purple_cache_dir:
- *
- * Returns the purple cache directory according to XDG Base Directory Specification.
- * This is usually $HOME/.cache/purple.
- * If custom user dir was specified then this is cache
- * sub-directory of DIR argument passed to -c option.
- *
- * Returns: The purple cache directory.
- */
-const gchar *purple_cache_dir(void);
-
-/**
- * purple_config_dir:
- *
- * Returns the purple configuration directory according to XDG Base Directory Specification.
- * This is usually $HOME/.config/purple.
- * If custom user dir was specified then this is config
- * sub-directory of DIR argument passed to -c option.
- *
- * Returns: The purple configuration directory.
- */
-const gchar *purple_config_dir(void);
-
-/**
- * purple_data_dir:
- *
- * Returns the purple data directory according to XDG Base Directory Specification.
- * This is usually $HOME/.local/share/purple.
- * If custom user dir was specified then this is data
- * sub-directory of DIR argument passed to -c option.
- *
- * Returns: The purple data directory.
- */
-const gchar *purple_data_dir(void);
-
-/**
- * purple_util_set_user_dir:
- * @dir: The custom settings directory
- *
- * Define a custom purple settings directory, overriding the default (user's home directory/.purple)
- */
-void purple_util_set_user_dir(const char *dir);
-
 /**
  * purple_util_write_data_to_file:
  * @filename: The basename of the file to write in the purple_user_dir.
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -29,42 +29,20 @@
 #include "prefs.h"
 #include "purpleaccountmanager.h"
 #include "purpleconversation.h"
+#include "purplepath.h"
 #include "purpleprotocol.h"
 #include "purpleprotocolclient.h"
 #include "util.h"
 
 #include <json-glib/json-glib.h>
 
-static char *custom_user_dir = NULL;
-static char *user_dir = NULL;
-static gchar *cache_dir = NULL;
-static gchar *config_dir = NULL;
-static gchar *data_dir = NULL;
-
 void
-purple_util_init(void)
-{
+purple_util_init(void) {
 }
 
 void
-purple_util_uninit(void)
-{
-	/* Free these so we don't have leaks at shutdown. */
-
-	g_free(custom_user_dir);
-	custom_user_dir = NULL;
-
-	g_free(user_dir);
-	user_dir = NULL;
-
-	g_free(cache_dir);
-	cache_dir = NULL;
-
-	g_free(config_dir);
-	config_dir = NULL;
-
-	g_free(data_dir);
-	data_dir = NULL;
+purple_util_uninit(void) {
+	purple_util_set_user_dir(NULL);
 }
 
 /**************************************************************************
@@ -460,70 +438,6 @@
 /**************************************************************************
  * Path/Filename Functions
  **************************************************************************/
-const char *
-purple_home_dir(void)
-{
-#ifndef _WIN32
-	return g_get_home_dir();
-#else
-	return wpurple_home_dir();
-#endif
-}
-
-/* Returns the argument passed to -c IFF it was present, or ~/.purple. */
-const char *
-purple_user_dir(void)
-{
-	if (custom_user_dir != NULL)
-		return custom_user_dir;
-	else if (!user_dir)
-		user_dir = g_build_filename(purple_home_dir(), ".purple", NULL);
-
-	return user_dir;
-}
-
-static const gchar *
-purple_xdg_dir(gchar **xdg_dir, const gchar *xdg_base_dir, const gchar *xdg_type)
-{
-	if (!*xdg_dir) {
-		if (!custom_user_dir) {
-			*xdg_dir = g_build_filename(xdg_base_dir, "purple", NULL);
-		} else {
-			*xdg_dir = g_build_filename(custom_user_dir, xdg_type, NULL);
-		}
-	}
-
-	return *xdg_dir;
-}
-
-const gchar *
-purple_cache_dir(void)
-{
-	return purple_xdg_dir(&cache_dir, g_get_user_cache_dir(), "cache");
-}
-
-const gchar *
-purple_config_dir(void)
-{
-	return purple_xdg_dir(&config_dir, g_get_user_config_dir(), "config");
-}
-
-const gchar *
-purple_data_dir(void)
-{
-	return purple_xdg_dir(&data_dir, g_get_user_data_dir(), "data");
-}
-
-void purple_util_set_user_dir(const char *dir)
-{
-	g_free(custom_user_dir);
-
-	if (dir != NULL && *dir)
-		custom_user_dir = g_strdup(dir);
-	else
-		custom_user_dir = NULL;
-}
-
 static gboolean
 purple_util_write_data_to_file_common(const char *dir, const char *filename, const char *data, gssize size)
 {
diff --git a/po/POTFILES.in b/po/POTFILES.in
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -255,6 +255,7 @@
 libpurple/purplemessage.c
 libpurple/purplenoopcredentialprovider.c
 libpurple/purpleoptions.c
+libpurple/purplepath.c
 libpurple/purplepresence.c
 libpurple/purpleplugininfo.c
 libpurple/purpleprotocol.c
