Missing Glib::get_user_runtime_dir() function
The g_get_user_runtime_dir()
function was introduced in glib
2.28. It is supposed to return a path to the XDG_RUNTIME_DIR
directory.
Returns a directory that is unique to the current user on the local system.
However, glibmm
doesn't provide anything like this. There is no Glib::get_user_runtime_dir()
or anything similar.
https://github.com/GNOME/glib/blob/3ad375a629c91a27d0165a31f0ed298fd553de0a/glib/gutils.h
https://github.com/GNOME/glib/blob/3ad375a629c91a27d0165a31f0ed298fd553de0a/glib/gutils.c
Why? Is this an oversight?
Example values:
user_runtime_dir: /run/user/1000
user_cache_dir: /home/scx/.var/app/org.example.glibmmtest/cache
tmp_dir: /tmp
Temporary patch:
diff --git a/glib/src/miscutils.ccg b/glib/src/miscutils.ccg
index 90043af..e061631 100644
--- a/glib/src/miscutils.ccg
+++ b/glib/src/miscutils.ccg
@@ -146,6 +146,12 @@ get_user_cache_dir()
return convert_const_gchar_ptr_to_stdstring(g_get_user_cache_dir());
}
+std::string
+get_user_runtime_dir()
+{
+ return convert_const_gchar_ptr_to_stdstring(g_get_user_runtime_dir());
+}
+
bool
path_is_absolute(const std::string& filename)
{
diff --git a/glib/src/miscutils.hg b/glib/src/miscutils.hg
index ffc87f3..d1748cf 100644
--- a/glib/src/miscutils.hg
+++ b/glib/src/miscutils.hg
@@ -244,6 +244,15 @@ std::vector<std::string> get_system_config_dirs();
*/
std::string get_user_cache_dir();
+/** Returns a directory that is unique to the current user on the local system.
+ *
+ * This is the directory specified in the XDG_RUNTIME_DIR environment variable.
+ * In the case that this variable is not set, we return the value of g_get_user_cache_dir(), after verifying that it exists.
+ *
+ * @newin{2,64}
+ */
+std::string get_user_runtime_dir();
+
/** Returns @c true if the given @a filename is an absolute file name, i.e.\ it
* contains a full path from the root directory such as <tt>"/usr/local"</tt>
* on UNIX or <tt>"C:\\windows"</tt> on Windows systems.
PR is on the way.