aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert2019-08-30 00:24:07 -0700
committerPaul Eggert2019-08-30 00:24:47 -0700
commit44f15b63dbe9a45921573197e08c8aaaed08412a (patch)
tree004ad6c462f0ceb19b5f24c535fcaa614d21043a /lib-src
parenta4144af909c3a6baf381659bf158e254b28ee002 (diff)
downloademacs-44f15b63dbe9a45921573197e08c8aaaed08412a.tar.gz
emacs-44f15b63dbe9a45921573197e08c8aaaed08412a.zip
emacsclient: adjust to new config file location
* lib-src/emacsclient.c (open_config): New arg XDG, to respect XDG_CONFIG_HOME, consistently with Emacs proper. Caller changed. Use XDG convention if available, falling back on the old names if not.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/emacsclient.c47
1 files changed, 32 insertions, 15 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index ba2721e8bc9..e9469f77c5e 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -914,22 +914,38 @@ initialize_sockets (void)
914#endif /* WINDOWSNT */ 914#endif /* WINDOWSNT */
915 915
916 916
917/* If the home directory is HOME, return the configuration file with 917/* If the home directory is HOME, and XDG_CONFIG_HOME's value is XDG,
918 basename CONFIG_FILE. Fail if there is no home directory or if the 918 return the configuration file with basename CONFIG_FILE. Fail if
919 configuration file could not be opened. */ 919 the configuration file could not be opened. */
920 920
921static FILE * 921static FILE *
922open_config (char const *home, char const *config_file) 922open_config (char const *home, char const *xdg, char const *config_file)
923{ 923{
924 if (!home) 924 ptrdiff_t xdgsubdirsize = xdg ? strlen (xdg) + sizeof "/emacs/server/" : 0;
925 return NULL; 925 ptrdiff_t homesuffixsizemax = max (sizeof "/.config/emacs/server/",
926 ptrdiff_t homelen = strlen (home); 926 sizeof "/.emacs.d/server/");
927 static char const emacs_d_server[] = "/.emacs.d/server/"; 927 ptrdiff_t homesubdirsizemax = home ? strlen (home) + homesuffixsizemax : 0;
928 ptrdiff_t suffixsize = sizeof emacs_d_server + strlen (config_file); 928 char *configname = xmalloc (max (xdgsubdirsize, homesubdirsizemax)
929 char *configname = xmalloc (homelen + suffixsize); 929 + strlen (config_file));
930 strcpy (stpcpy (stpcpy (configname, home), emacs_d_server), config_file); 930 FILE *config;
931 931 if (xdg || home)
932 FILE *config = fopen (configname, "rb"); 932 {
933 strcpy ((xdg
934 ? stpcpy (stpcpy (configname, xdg), "/emacs/server/")
935 : stpcpy (stpcpy (configname, home), "/.config/emacs/server/")),
936 config_file);
937 config = fopen (configname, "rb");
938 }
939 else
940 config = NULL;
941
942 if (! config && home)
943 {
944 strcpy (stpcpy (stpcpy (configname, home), "/.emacs.d/server/"),
945 config_file);
946 config = fopen (configname, "rb");
947 }
948
933 free (configname); 949 free (configname);
934 return config; 950 return config;
935} 951}
@@ -949,10 +965,11 @@ get_server_config (const char *config_file, struct sockaddr_in *server,
949 config = fopen (config_file, "rb"); 965 config = fopen (config_file, "rb");
950 else 966 else
951 { 967 {
952 config = open_config (egetenv ("HOME"), config_file); 968 char const *xdg = egetenv ("XDG_CONFIG_HOME");
969 config = open_config (egetenv ("HOME"), xdg, config_file);
953#ifdef WINDOWSNT 970#ifdef WINDOWSNT
954 if (!config) 971 if (!config)
955 config = open_config (egetenv ("APPDATA"), config_file); 972 config = open_config (egetenv ("APPDATA"), xdg, config_file);
956#endif 973#endif
957 } 974 }
958 975