From cb7db5bbd56f587a35c1861282c46d424fee0b38 Mon Sep 17 00:00:00 2001 From: Lénaïc Huard Date: Sat, 4 Sep 2021 22:54:58 +0200 Subject: cache.h: Introduce a generic "xdg_config_home_for(…)" function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current implementation of `xdg_config_home(filename)` returns `$XDG_CONFIG_HOME/git/$filename`, with the `git` subdirectory inserted between the `XDG_CONFIG_HOME` environment variable and the parameter. This patch introduces a `xdg_config_home_for(subdir, filename)` function which is more generic. It only concatenates "$XDG_CONFIG_HOME", or "$HOME/.config" if the former isn’t defined, with the parameters, without adding `git` in between. `xdg_config_home(filename)` is now implemented by calling `xdg_config_home_for("git", filename)` but this new generic function can be used to compute the configuration directory of other programs. Signed-off-by: Lénaïc Huard Acked-by: Derrick Stolee Signed-off-by: Junio C Hamano --- cache.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index ba04ff8bd3..2a0fb3e4ba 100644 --- a/cache.h +++ b/cache.h @@ -1286,6 +1286,13 @@ int is_ntfs_dotmailmap(const char *name); */ int looks_like_command_line_option(const char *str); +/** + * Return a newly allocated string with the evaluation of + * "$XDG_CONFIG_HOME/$subdir/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise + * "$HOME/.config/$subdir/$filename". Return NULL upon error. + */ +char *xdg_config_home_for(const char *subdir, const char *filename); + /** * Return a newly allocated string with the evaluation of * "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise -- cgit 1.2.3-korg