From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id wyhwFHkRfl8SUQAAWB0awg (envelope-from ) for ; Wed, 07 Oct 2020 15:05:29 -0400 Received: by simark.ca (Postfix, from userid 112) id 457131EF7B; Wed, 7 Oct 2020 15:05:29 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 881F21EF4A for ; Wed, 7 Oct 2020 15:05:28 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ED0963851C0A; Wed, 7 Oct 2020 19:05:27 +0000 (GMT) Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id DDD8F385781A for ; Wed, 7 Oct 2020 19:05:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DDD8F385781A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x42f.google.com with SMTP id k10so3542998wru.6 for ; Wed, 07 Oct 2020 12:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ah7t5DWdQJdqEbqvwymn5sRAsJOnmAr96UfYXdYZBlw=; b=O4uNv5N3uZy+V1OjfaPF+wU6VCbYYUufsnlCltz22WyrgTVxrDPlhhdQYD7vhyjV7A gh1vmLXDFAP8YxkoHPFucmU5cs5Zaq1CFJkuvgezCnKp5EoPKg0lpMk8QCOMWn3eF2tH xJPpKtFgJA19k4PpOv91yihWBKh4/uZ+NPxX5jCpDvxPo5BsY8Nc2UClEm5g2n67bJZN L1IqMaAI7isO19AIC+FlKzRQEA8l+q6rn5GW1LxNr9KWw1GyHrdTd+dod86uAeAlj/ql kHCapP52NkEzXjb0yecMMvoqBkpiwzkhR6nwx/r+h3+pw/pnCWen6XIqZTGgpUccXdzz 72Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ah7t5DWdQJdqEbqvwymn5sRAsJOnmAr96UfYXdYZBlw=; b=MJzqWkxnVWKvSqwE6ksU62kTlrapHKpXfbx8e6PYZkcyPEwGrSUIJn3mnWZOhsk7H5 p7h5upSKkiVMlvlA98ZYhGbZAywP+PfziAJuG6m5xCz3l/RipXvVH7t54pl6VlQ8LUGU KeogKtst3LH2YCDlVz8iB3GHZXnG5YbxfHk+jX6xCZ4qWo6a0lCNHtLlCbMgtlR7DSbj QWIQIzZw2K3H80njZATk3JlDHJg0C2n3H/i+GdnnxBzgVy8tccqOuIUvf0aGQkOvz/sz lX/d8TdtGTrq+buD9sef558k8DZ5ylDl62WhBXlKdneOKUxiSiE7zXX0rkmBfhTaA2ls nVXw== X-Gm-Message-State: AOAM5313w6DtT9dZsuQYPLrNEhCXg1xr94KvDK9A7qpdryoa3stZx3yo 7C2d0HLVYJPALBROy9wczVGq+6vv+GssoQ== X-Google-Smtp-Source: ABdhPJwqcB6HV7RNA/NvT4B/eBGUcQS3guWR25fJTKqnw/Ez4T030OI662Oy8IXJMe9J8lRwjwXXBg== X-Received: by 2002:a5d:680a:: with SMTP id w10mr5275155wru.5.1602097524397; Wed, 07 Oct 2020 12:05:24 -0700 (PDT) Received: from localhost (host109-151-14-50.range109-151.btcentralplus.com. [109.151.14.50]) by smtp.gmail.com with ESMTPSA id e18sm3928173wrx.50.2020.10.07.12.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2020 12:05:23 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PATCH 1/7] Add get_standard_config_dir function Date: Wed, 7 Oct 2020 21:05:05 +0100 Message-Id: <5bb3f6f023b00a8653de9ec95a6c2ff73d943864.1601927355.git.andrew.burgess@embecosm.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , Cc: Tom Tromey Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" From: Tom Tromey 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 * 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.25.4