Skip to content

Commit 2edeff7

Browse files
committed
Settings_new() code shrink
No need to temporarily duplicate the XDG_CONFIG_HOME path string. Note that I didn't simplify or leave out the allocation of "$XDG_CONFIG_HOME/htop" or "$HOME/.config/htop" string because I suspect this string might be reused in the future. Signed-off-by: Kang-Che Sung <[email protected]>
1 parent 4a61e89 commit 2edeff7

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

Settings.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ int Settings_write(const Settings* this, bool onCrash) {
687687
return 0;
688688
} else {
689689
// Prepare temp filename
690-
xAsprintf(&tmpFilename, "%s.tmp.XXXXXX", this->filename);
690+
tmpFilename = String_cat(this->filename, ".tmp.XXXXXX");
691691

692692
// Create ancestor directories with mode 0700
693693
mode_t cur_umask = umask(S_IRWXG | S_IRWXO);
@@ -883,19 +883,14 @@ Settings* Settings_new(const Machine* host, Hashtable* dynamicMeters, Hashtable*
883883
home = (pw && pw->pw_dir && pw->pw_dir[0] == '/') ? pw->pw_dir : "";
884884
}
885885
const char* xdgConfigHome = getenv("XDG_CONFIG_HOME");
886-
char* configDir = NULL;
887886
char* htopDir = NULL;
888887
if (xdgConfigHome && xdgConfigHome[0] == '/') {
889-
this->initialFilename = String_cat(xdgConfigHome, "/htop/htoprc");
890-
configDir = xStrdup(xdgConfigHome);
891888
htopDir = String_cat(xdgConfigHome, "/htop");
892889
} else {
893-
this->initialFilename = String_cat(home, CONFIGDIR "/htop/htoprc");
894-
configDir = String_cat(home, CONFIGDIR);
895890
htopDir = String_cat(home, CONFIGDIR "/htop");
896891
}
892+
this->initialFilename = String_cat(htopDir, "/htoprc");
897893
free(htopDir);
898-
free(configDir);
899894

900895
legacyDotfile = String_cat(home, "/.htoprc");
901896
}

0 commit comments

Comments
 (0)