From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 1/7] Add get_standard_config_dir function
Date: Wed, 7 Oct 2020 21:05:05 +0100 [thread overview]
Message-ID: <5bb3f6f023b00a8653de9ec95a6c2ff73d943864.1601927355.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1601927355.git.andrew.burgess@embecosm.com>
From: Tom Tromey <tom@tromey.com>
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.
---
gdbsupport/ChangeLog | 5 +++++
gdbsupport/pathstuff.cc | 32 ++++++++++++++++++++++++++++++++
gdbsupport/pathstuff.h | 14 ++++++++++++++
3 files changed, 51 insertions(+)
diff --git a/gdbsupport/pathstuff.cc b/gdbsupport/pathstuff.cc
index 1f60fd0c986..9fb5e5cf614 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 *
diff --git a/gdbsupport/pathstuff.h b/gdbsupport/pathstuff.h
index 4bc0d892119..85241bc8c7c 100644
--- a/gdbsupport/pathstuff.h
+++ b/gdbsupport/pathstuff.h
@@ -85,6 +85,20 @@ extern std::string get_standard_cache_dir ();
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. */
--
2.25.4
next prev parent reply other threads:[~2020-10-07 19:05 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-07 20:05 [PATCH 0/7] Adding startup files to GDB Andrew Burgess
2020-10-07 20:05 ` Andrew Burgess [this message]
2020-10-07 20:05 ` [PATCH 2/7] gdb: use get_standard_config_dir when looking for .gdbinit Andrew Burgess
2020-10-08 6:52 ` Eli Zaretskii via Gdb-patches
2020-11-02 10:20 ` Andrew Burgess
2020-10-22 19:07 ` Tom Tromey
2020-11-09 13:52 ` Tom Tromey
2020-11-09 13:55 ` Tom Tromey
2020-10-07 20:05 ` [PATCH 3/7] gdb: new function to wrap up executing command line scripts/commands Andrew Burgess
2020-10-08 15:25 ` Aktemur, Tankut Baris via Gdb-patches
2020-11-02 9:48 ` Andrew Burgess
2020-10-22 19:08 ` Tom Tromey
2020-10-07 20:05 ` [PATCH 4/7] gdb: process startup files and startup command line options Andrew Burgess
2020-10-08 6:28 ` Eli Zaretskii via Gdb-patches
2020-10-07 20:05 ` [PATCH 5/7] gdb: add mechanism to auto-save startup options Andrew Burgess
2020-10-08 6:36 ` Eli Zaretskii via Gdb-patches
2020-10-07 20:05 ` [PATCH 6/7] Let the user control the startup style Andrew Burgess
2020-10-08 6:40 ` Eli Zaretskii via Gdb-patches
2020-10-07 20:05 ` [PATCH 7/7] Add "set startup-quietly" Andrew Burgess
2020-10-08 6:44 ` Eli Zaretskii via Gdb-patches
2020-10-08 6:56 ` [PATCH 0/7] Adding startup files to GDB Eli Zaretskii via Gdb-patches
2020-10-22 19:02 ` Tom Tromey
2020-10-28 15:29 ` Andrew Burgess
2021-01-11 16:45 ` Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5bb3f6f023b00a8653de9ec95a6c2ff73d943864.1601927355.git.andrew.burgess@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox