aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport/pathstuff.cc
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-07-05 13:02:40 -0600
committerAndrew Burgess <andrew.burgess@embecosm.com>2020-11-02 17:42:10 +0000
commit8768c3e3629657d9728487c680b173868baeee7f (patch)
tree9a8e29f261a25438a33f59a5950d499b6ecfb718 /gdbsupport/pathstuff.cc
parent5b3d3560e9e867f652ff622863cbac267455f726 (diff)
downloadbinutils-8768c3e3629657d9728487c680b173868baeee7f.zip
binutils-8768c3e3629657d9728487c680b173868baeee7f.tar.gz
binutils-8768c3e3629657d9728487c680b173868baeee7f.tar.bz2
Add get_standard_config_dir function
This adds a new get_standard_config_dir, which returns the name of the configuration directory. In XDG, this is ~/.config/gdb/. Future patches will make use of this. 2020-07-05 Tom Tromey <tom@tromey.com> * pathstuff.h (get_standard_config_dir): Declare. * pathstuff.cc (get_standard_config_dir): New function.
Diffstat (limited to 'gdbsupport/pathstuff.cc')
-rw-r--r--gdbsupport/pathstuff.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/gdbsupport/pathstuff.cc b/gdbsupport/pathstuff.cc
index 1f60fd0..9fb5e5c 100644
--- a/gdbsupport/pathstuff.cc
+++ b/gdbsupport/pathstuff.cc
@@ -266,6 +266,38 @@ get_standard_temp_dir ()
#endif
}
+/* See pathstuff.h. */
+
+std::string
+get_standard_config_dir ()
+{
+#ifdef __APPLE__
+#define HOME_CONFIG_DIR "Library/Preferences"
+#else
+#define HOME_CONFIG_DIR ".config"
+#endif
+
+#ifndef __APPLE__
+ const char *xdg_config_home = getenv ("XDG_CONFIG_HOME");
+ if (xdg_config_home != NULL)
+ {
+ /* Make sure the path is absolute and tilde-expanded. */
+ gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (xdg_config_home));
+ return string_printf ("%s/gdb", abs.get ());
+ }
+#endif
+
+ const char *home = getenv ("HOME");
+ if (home != NULL)
+ {
+ /* Make sure the path is absolute and tilde-expanded. */
+ gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (home));
+ return string_printf ("%s/" HOME_CONFIG_DIR "/gdb", abs.get ());
+ }
+
+ return {};
+}
+
/* See gdbsupport/pathstuff.h. */
const char *