[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * info/infomap.c (locate_init_file): Check throug
From: |
Gavin D. Smith |
Subject: |
branch master updated: * info/infomap.c (locate_init_file): Check through XDG_CONFIG_DIRS as a last resort, using /etc/xdg as a default value. (fetch_user_maps): Accommodate null return value from locate_init_file. |
Date: |
Sun, 29 Oct 2023 13:24:00 -0400 |
This is an automated email from the git hooks/post-receive script.
gavin pushed a commit to branch master
in repository texinfo.
The following commit(s) were added to refs/heads/master by this push:
new ad0dcda0c3 * info/infomap.c (locate_init_file): Check through
XDG_CONFIG_DIRS as a last resort, using /etc/xdg as a default value.
(fetch_user_maps): Accommodate null return value from locate_init_file.
ad0dcda0c3 is described below
commit ad0dcda0c39b2b93838dc6b9f4af0607e9a80f9b
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun Oct 29 17:23:51 2023 +0000
* info/infomap.c (locate_init_file): Check through
XDG_CONFIG_DIRS as a last resort, using /etc/xdg as a default
value.
(fetch_user_maps): Accommodate null return value from
locate_init_file.
---
ChangeLog | 8 ++++++++
info/infomap.c | 48 ++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 037b85e87d..b5ac3b953e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-10-29 Gavin Smith <gavinsmith0123@gmail.com>
+
+ * info/infomap.c (locate_init_file): Check through
+ XDG_CONFIG_DIRS as a last resort, using /etc/xdg as a default
+ value.
+ (fetch_user_maps): Accommodate null return value from
+ locate_init_file.
+
2023-10-29 Gavin Smith <gavinsmith0123@gmail.com>
* doc/info-stnd.texi (Custom Key Bindings): Describe looking
diff --git a/info/infomap.c b/info/infomap.c
index 30d66a6bf8..e475af9cde 100644
--- a/info/infomap.c
+++ b/info/infomap.c
@@ -560,7 +560,11 @@ static int sup_info, sup_ea;
-/* Locate init file. Return value to be freed by caller. */
+/* Locate init file. Return value to be freed by caller.
+
+ See the "XDG Base Directory Specification" at
+ https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
+*/
char *
locate_init_file (void)
{
@@ -599,8 +603,7 @@ locate_init_file (void)
xdg_config_home, PACKAGE, INFOKEY_FILE);
free (xdg_config_home);
- int status = stat (filename, &finfo);
- if (status == 0)
+ if (stat (filename, &finfo) == 0)
return filename;
free (filename);
}
@@ -623,7 +626,39 @@ locate_init_file (void)
filename = xstrdup (DOT_INFOKEY_FILE); /* try current directory */
#endif
- return filename;
+ if (filename)
+ {
+ if (stat (filename, &finfo) == 0)
+ return filename;
+ free (filename);
+ }
+
+ /* Finally, check through XDG_CONFIG_DIRS. */
+
+ char *xdg_config_dirs = getenv ("XDG_CONFIG_DIRS");
+ if (!xdg_config_dirs)
+ xdg_config_dirs = "/etc/xdg";
+
+ char *xdg_config_dirs_split = xstrdup (xdg_config_dirs);
+
+ char *dir = strtok (xdg_config_dirs_split, ":");
+ while (dir)
+ {
+ filename = xmalloc (strlen (dir) + 1
+ + strlen (PACKAGE) + 1
+ + strlen (INFOKEY_FILE) + 1);
+ sprintf (filename, "%s/%s/%s", dir, PACKAGE, INFOKEY_FILE);
+ if (stat (filename, &finfo) == 0)
+ {
+ free (xdg_config_dirs_split);
+ return filename;
+ }
+ free (filename);
+ dir = strtok (NULL, ":");
+ }
+
+ free (xdg_config_dirs_split);
+ return 0;
}
@@ -634,7 +669,7 @@ static int
fetch_user_maps (char *init_file)
{
char *filename = NULL;
- FILE *inf;
+ FILE *inf = NULL;
/* In infokey.c */
int compile (FILE *fp, const char *filename, int *, int *);
@@ -645,7 +680,8 @@ fetch_user_maps (char *init_file)
else
filename = locate_init_file ();
- inf = fopen (filename, "r");
+ if (filename)
+ inf = fopen (filename, "r");
if (!inf)
{
free (filename);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * info/infomap.c (locate_init_file): Check through XDG_CONFIG_DIRS as a last resort, using /etc/xdg as a default value. (fetch_user_maps): Accommodate null return value from locate_init_file.,
Gavin D. Smith <=