summaryrefslogtreecommitdiff
path: root/src/xrdb.c
diff options
context:
space:
mode:
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,
}
-static char *
-gethomedir (void)
-{
- struct passwd *pw;
- char *ptr;
- char *copy;
-
- if ((ptr = getenv ("HOME")) == NULL)
- {
- if ((ptr = getenv ("LOGNAME")) != NULL
- || (ptr = getenv ("USER")) != NULL)
- pw = getpwnam (ptr);
- else
- pw = getpwuid (getuid ());
-
- if (pw)
- ptr = pw->pw_dir;
- }
-
- if (ptr == NULL)
- return xstrdup ("/");
-
- ptrdiff_t len = strlen (ptr);
- copy = xmalloc (len + 2);
- strcpy (copy + len, "/");
- return memcpy (copy, ptr, len);
-}
-
-
/* Find the first element of SEARCH_PATH which exists and is readable,
after expanding the %-escapes. Return 0 if we didn't find any, and
the path name of the one we found otherwise. */
@@ -316,12 +287,11 @@ get_user_app (const char *class)
if (! db)
{
/* Check in the home directory. This is a bit of a hack; let's
- hope one's home directory doesn't contain any %-escapes. */
- char *home = gethomedir ();
+ hope one's home directory doesn't contain ':' or '%'. */
+ char const *home = get_homedir ();
db = search_magic_path (home, class, "%L/%N");
if (! db)
db = search_magic_path (home, class, "%N");
- xfree (home);
}
return db;
@@ -346,10 +316,9 @@ get_user_db (Display *display)
else
{
/* Use ~/.Xdefaults. */
- char *home = gethomedir ();
- ptrdiff_t homelen = strlen (home);
- char *filename = xrealloc (home, homelen + sizeof xdefaults);
- strcpy (filename + homelen, xdefaults);
+ char const *home = get_homedir ();
+ char *filename = xmalloc (strlen (home) + 1 + sizeof xdefaults);
+ splice_dir_file (filename, home, xdefaults);
db = XrmGetFileDatabase (filename);
xfree (filename);
}
@@ -380,13 +349,12 @@ get_environ_db (void)
if (STRINGP (system_name))
{
/* Use ~/.Xdefaults-HOSTNAME. */
- char *home = gethomedir ();
- ptrdiff_t homelen = strlen (home);
- ptrdiff_t filenamesize = (homelen + sizeof xdefaults
- + 1 + SBYTES (system_name));
- p = filename = xrealloc (home, filenamesize);
- lispstpcpy (stpcpy (stpcpy (filename + homelen, xdefaults), "-"),
- system_name);
+ char const *home = get_homedir ();
+ p = filename = xmalloc (strlen (home) + 1 + sizeof xdefaults
+ + 1 + SBYTES (system_name));
+ char *e = splice_dir_file (p, home, xdefaults);
+ *e++ = '/';
+ lispstpcpy (e, system_name);
}
}