Commit 83af542d authored by antma's avatar antma

close /etc/passwd file handle right after evaluating home directory

parent 3795a776
...@@ -120,16 +120,25 @@ void set_terminal_attributes (void) { ...@@ -120,16 +120,25 @@ void set_terminal_attributes (void) {
/* }}} */ /* }}} */
char *get_home_directory (void) { char *get_home_directory (void) {
static char *home_directory = NULL;
if (home_directory != NULL) {
return home_directory;
}
struct passwd *current_passwd; struct passwd *current_passwd;
uid_t user_id; uid_t user_id;
setpwent (); setpwent ();
user_id = getuid (); user_id = getuid ();
while ((current_passwd = getpwent ())) { while ((current_passwd = getpwent ())) {
if (current_passwd->pw_uid == user_id) { if (current_passwd->pw_uid == user_id) {
return current_passwd->pw_dir; home_directory = tstrdup (current_passwd->pw_dir);
break;
} }
} }
return ""; endpwent ();
if (home_directory == NULL) {
home_directory = tstrdup (".");
}
return home_directory;
} }
char *get_config_directory (void) { char *get_config_directory (void) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment