From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway36.websitewelcome.com (gateway36.websitewelcome.com [192.185.201.2]) by sourceware.org (Postfix) with ESMTPS id BD015395C859 for ; Tue, 23 Jun 2020 13:20:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BD015395C859 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 2262340153B9E for ; Tue, 23 Jun 2020 07:41:34 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id niqPj9R7PBb5dniqPjRCPS; Tue, 23 Jun 2020 08:20:09 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=jETvqbyPHGHeRqaWUKkHWsTb+Te2xtR8+7lWdTSDHxc=; b=wg2calz/TSPPjFC1Tx7y1IBG7s Pk1YKSknYV2OxS68djCQhujFWhbNAuo0rtG9E/deKd59c06oQL6Ps6p9B7iI04IKxTLymaAzLcO0c v4pK872KNT/gHEtKS2rTo+tOz; Received: from 174-16-104-48.hlrn.qwest.net ([174.16.104.48]:45100 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1jniqP-002fzZ-E6; Tue, 23 Jun 2020 07:20:09 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 4/7] Add get_standard_config_dir function Date: Tue, 23 Jun 2020 07:20:03 -0600 Message-Id: <20200623132006.15863-5-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200623132006.15863-1-tom@tromey.com> References: <20200623132006.15863-1-tom@tromey.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 174.16.104.48 X-Source-L: No X-Exim-ID: 1jniqP-002fzZ-E6 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174-16-104-48.hlrn.qwest.net (bapiya.Home) [174.16.104.48]:45100 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3037.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Jun 2020 13:20:24 -0000 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-06-22 Tom Tromey * 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 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 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.17.2