diff options
author | Jérémie Courrèges-Anglas <jca@wxcvbn.org> | 2014-03-04 02:44:15 +0100 |
---|---|---|
committer | Jérémie Courrèges-Anglas <jca@wxcvbn.org> | 2014-03-04 02:44:15 +0100 |
commit | c51dd419f9d40facf516558510704891c0cf66b6 (patch) | |
tree | c25a9fc19be6332c66cdb800c94e31200eac6f64 /src/main.c | |
parent | f010d26cbad242f2a98c2d67e5100bdf9387addb (diff) | |
download | ratpoison-c51dd419f9d40facf516558510704891c0cf66b6.zip |
get_homedir(), checks HOME and the password database
* ensures that the resulting home directory isn't the empty string
(else returns NULL)
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 40 |
1 files changed, 28 insertions, 12 deletions
@@ -404,10 +404,35 @@ read_rc_file (FILE *file) free (line); } +const char * +get_homedir (void) +{ + char *homedir; + + homedir = getenv ("HOME"); + if (homedir != NULL && homedir[0] == '\0') + homedir = NULL; + +#if defined (HAVE_PWD_H) && defined (HAVE_GETPWUID) + if (homedir == NULL) + { + struct passwd *pw; + + pw = getpwuid (getuid ()); + if (pw != NULL) + homedir = pw->pw_dir; + + if (homedir != NULL && homedir[0] == '\0') + homedir = NULL; + } +#endif + + return homedir; +} + static int read_startup_files (char *alt_rcfile) { - char *homedir; FILE *fileptr = NULL; if (alt_rcfile) @@ -423,18 +448,9 @@ read_startup_files (char *alt_rcfile) { /* first check $HOME/.ratpoisonrc and if that does not exist then try $sysconfdir/ratpoisonrc */ + const char *homedir; - homedir = getenv ("HOME"); -#if defined (HAVE_PWD_H) && defined (HAVE_GETPWUID) - if (!homedir) - { - struct passwd *pw; - - pw = getpwuid (getuid ()); - if (pw) - homedir = pw->pw_dir; - } -#endif + homedir = get_homedir (); if (!homedir) PRINT_ERROR (("ratpoison: no home directory!?\n")); |