close /etc/passwd file handle right after evaluating home directory
This commit is contained in:
parent
bb24fba98f
commit
35923482bc
1 changed files with 11 additions and 2 deletions
13
main.c
13
main.c
|
@ -120,16 +120,25 @@ void set_terminal_attributes (void) {
|
|||
/* }}} */
|
||||
|
||||
char *get_home_directory (void) {
|
||||
static char *home_directory = NULL;
|
||||
if (home_directory != NULL) {
|
||||
return home_directory;
|
||||
}
|
||||
struct passwd *current_passwd;
|
||||
uid_t user_id;
|
||||
setpwent ();
|
||||
user_id = getuid ();
|
||||
while ((current_passwd = getpwent ())) {
|
||||
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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue