+2020-11-02 Tom Tromey <tom@tromey.com>
+
+ * pathstuff.h (get_standard_config_dir): Declare.
+ * pathstuff.cc (get_standard_config_dir): New function.
+
2020-11-02 Simon Marchi <simon.marchi@efficios.com>
* common-exceptions.h: Fix indentation.
#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 *
extern std::string get_standard_temp_dir ();
+/* Get the usual user config directory for the current platform.
+
+ On Linux, it follows the XDG Base Directory specification: use
+ $XDG_CONFIG_HOME/gdb if the XDG_CONFIG_HOME environment variable is
+ defined, otherwise $HOME/.config.
+
+ On macOS, it follows the local convention and uses
+ ~/Library/Preferences/gdb.
+
+ The return value is absolute and tilde-expanded. Return an empty
+ string if neither XDG_CONFIG_HOME (on Linux) or HOME are defined. */
+
+extern std::string get_standard_config_dir ();
+
/* Return the file name of the user's shell. Normally this comes from
the SHELL environment variable. */