aboutsummaryrefslogtreecommitdiffstats
path: root/src/xrdb.c
diff options
context:
space:
mode:
authorPaul Eggert2018-11-13 09:29:14 -0800
committerPaul Eggert2018-11-13 09:32:50 -0800
commit900276502fbb4dcabdabc5d7d24b4bc5645f2cf3 (patch)
tree4d6c17f5b3cea0f4d5dfbc7243eb6495269a7e56 /src/xrdb.c
parentce1fb157e840fd292c3db4632831c4514a663890 (diff)
downloademacs-900276502fbb4dcabdabc5d7d24b4bc5645f2cf3.tar.gz
emacs-900276502fbb4dcabdabc5d7d24b4bc5645f2cf3.zip
Act like POSIX sh if $HOME is relative
POSIX says sh ~/foo should act like $HOME/foo even if $HOME is relative, so be consistent with that (Bug#33255). * admin/merge-gnulib (GNULIB_MODULES): Add dosname. * src/buffer.c (init_buffer): Use emacs_wd to get initial working directory with slash appended if needed. (default-directory): Say it must be absolute. * src/emacs.c (emacs_wd): New global variable. (init_cmdargs): Dir arg is now char const *. (main): Set emacs_wd. * src/emacs.c (main) [NS_IMPL_COCOA]: * src/fileio.c (Fexpand_file_name): Use get_homedir instead of egetenv ("HOME"). * src/fileio.c: Include dosname.h, for IS_ABSOLUTE_FILE_NAME. (splice_dir_file, get_homedir): New functions. * src/xrdb.c (gethomedir): Remove. All callers changed to use get_homedir and splice_dir_file. * test/src/fileio-tests.el (fileio-tests--relative-HOME): New test.
Diffstat (limited to 'src/xrdb.c')
-rw-r--r--src/xrdb.c54
1 files changed, 11 insertions, 43 deletions
diff --git a/src/xrdb.c b/src/xrdb.c
index 4abf1ad84ed..87c2faf6598 100644
--- a/src/xrdb.c
+++ b/src/xrdb.c
@@ -202,35 +202,6 @@ magic_db (const char *string, ptrdiff_t string_len, const char *class,
202} 202}
203 203
204 204
205static char *
206gethomedir (void)
207{
208 struct passwd *pw;
209 char *ptr;
210 char *copy;
211
212 if ((ptr = getenv ("HOME")) == NULL)
213 {
214 if ((ptr = getenv ("LOGNAME")) != NULL
215 || (ptr = getenv ("USER")) != NULL)
216 pw = getpwnam (ptr);
217 else
218 pw = getpwuid (getuid ());
219
220 if (pw)
221 ptr = pw->pw_dir;
222 }
223
224 if (ptr == NULL)
225 return xstrdup ("/");
226
227 ptrdiff_t len = strlen (ptr);
228 copy = xmalloc (len + 2);
229 strcpy (copy + len, "/");
230 return memcpy (copy, ptr, len);
231}
232
233
234/* Find the first element of SEARCH_PATH which exists and is readable, 205/* Find the first element of SEARCH_PATH which exists and is readable,
235 after expanding the %-escapes. Return 0 if we didn't find any, and 206 after expanding the %-escapes. Return 0 if we didn't find any, and
236 the path name of the one we found otherwise. */ 207 the path name of the one we found otherwise. */
@@ -316,12 +287,11 @@ get_user_app (const char *class)
316 if (! db) 287 if (! db)
317 { 288 {
318 /* Check in the home directory. This is a bit of a hack; let's 289 /* Check in the home directory. This is a bit of a hack; let's
319 hope one's home directory doesn't contain any %-escapes. */ 290 hope one's home directory doesn't contain ':' or '%'. */
320 char *home = gethomedir (); 291 char const *home = get_homedir ();
321 db = search_magic_path (home, class, "%L/%N"); 292 db = search_magic_path (home, class, "%L/%N");
322 if (! db) 293 if (! db)
323 db = search_magic_path (home, class, "%N"); 294 db = search_magic_path (home, class, "%N");
324 xfree (home);
325 } 295 }
326 296
327 return db; 297 return db;
@@ -346,10 +316,9 @@ get_user_db (Display *display)
346 else 316 else
347 { 317 {
348 /* Use ~/.Xdefaults. */ 318 /* Use ~/.Xdefaults. */
349 char *home = gethomedir (); 319 char const *home = get_homedir ();
350 ptrdiff_t homelen = strlen (home); 320 char *filename = xmalloc (strlen (home) + 1 + sizeof xdefaults);
351 char *filename = xrealloc (home, homelen + sizeof xdefaults); 321 splice_dir_file (filename, home, xdefaults);
352 strcpy (filename + homelen, xdefaults);
353 db = XrmGetFileDatabase (filename); 322 db = XrmGetFileDatabase (filename);
354 xfree (filename); 323 xfree (filename);
355 } 324 }
@@ -380,13 +349,12 @@ get_environ_db (void)
380 if (STRINGP (system_name)) 349 if (STRINGP (system_name))
381 { 350 {
382 /* Use ~/.Xdefaults-HOSTNAME. */ 351 /* Use ~/.Xdefaults-HOSTNAME. */
383 char *home = gethomedir (); 352 char const *home = get_homedir ();
384 ptrdiff_t homelen = strlen (home); 353 p = filename = xmalloc (strlen (home) + 1 + sizeof xdefaults
385 ptrdiff_t filenamesize = (homelen + sizeof xdefaults 354 + 1 + SBYTES (system_name));
386 + 1 + SBYTES (system_name)); 355 char *e = splice_dir_file (p, home, xdefaults);
387 p = filename = xrealloc (home, filenamesize); 356 *e++ = '/';
388 lispstpcpy (stpcpy (stpcpy (filename + homelen, xdefaults), "-"), 357 lispstpcpy (e, system_name);
389 system_name);
390 } 358 }
391 } 359 }
392 360